Elasticsearch(13) match_phrase的使用

elasticsearch version: 7.10.1

match_phrase 语法

bash 复制代码
POST <index>/_search
{
  "query": {
    "match_phrase": {
      "<field_name>": {
        "query": "<your_search_phrase>",
        "slop": <max_distance>,
        "analyzer": "<analyzer_name>" (optional)
      }
    }
  }
}
  • <your_search_phrase>: 要搜索的确切短语
  • 可选参数,表示短语中词语的最大允许间隔数,默认值为0(即词语必须相邻)。

例题

场景

索引创建

bash 复制代码
PUT /product-reviews
{
  "mappings": {
    "properties": {
      "review": {
        "type": "text",
        "analyzer": "standard"
      }
    }
  }
}

文档插入

bash 复制代码
POST /product-reviews/_doc/
{
  "review": "This product is really easy to use and very efficient, I highly recommend it."
}
POST /product-reviews/_doc/
{
  "review": "This product is easy to use, efficient and has a great design."
}

POST /product-reviews/_doc/
{
  "review": "It's not just easy to use but also very energy-efficient, making it a top choice."
}

POST /product-reviews/_doc/
{
  "review": "Easy-to-use products are always my favorite, this one is highly efficient as well."
}

POST /product-reviews/_doc/
{
  "review": "I was surprised by how user-friendly and efficient this product turned out to be."
}

POST /product-reviews/_doc/
{
  "review": "The usability and efficiency of this product exceeded all my expectations."
}

查询语句

bash 复制代码
POST /product-reviews/_search
{
  "query": {
    "match_phrase": {
      "review": {
        "query": "easy to use efficient",
        "slop": 1
      }
    }
  }
}
相关推荐
Linux_Nathan5 小时前
【服务部署】ELFK架构篇之Elasticsearch
elk·elasticsearch·架构
TinpeaV5 小时前
Elasticsearch8(ES)保姆级菜鸟入门教程
大数据·spring boot·elasticsearch·搜索引擎·全文检索·postman
好好研究10 小时前
Git命令
大数据·git·elasticsearch
Elastic 中国社区官方博客11 小时前
使用 LangGraph.js 和 Elasticsearch 构建一个金融 AI 搜索工作流
大数据·人工智能·elasticsearch·搜索引擎·ai·金融·全文检索
W如Q扬11 小时前
filebeat使用dissect替换默认的的timestamp以及多行处理
elasticsearch·efk·filebeat
W如Q扬11 小时前
filebeat日志时区问题处理
elasticsearch·efk·filebeat
武子康11 小时前
大数据-176 Elasticsearch Filter DSL 全面实战:过滤查询、排序分页、高亮与批量操作
大数据·后端·elasticsearch
想个名字太难13 小时前
ElasticSearch编程操作
java·elasticsearch·全文检索
ganshenml1 天前
【GIT】Git 本地无法识别远程分支的原因与解决方法 not a valid ref
大数据·git·elasticsearch
The Straggling Crow1 天前
熟练版本控制 (Git)、CI/CD 流程。
git·elasticsearch·ci/cd