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
      }
    }
  }
}
相关推荐
重整旗鼓~1 小时前
6.IK分词器拓展词库
开发语言·elasticsearch
努力的小郑4 小时前
Elasticsearch 批量创建索引实践与优化建议
数据库·elasticsearch
想躺平的咸鱼干11 小时前
用idea进行数据同步
java·ide·后端·elasticsearch·中间件·intellij-idea
Elastic 中国社区官方博客2 天前
使用 Azure LLM Functions 与 Elasticsearch 构建更智能的查询体验
大数据·人工智能·elasticsearch·microsoft·搜索引擎·全文检索·azure
Mr.stupidCoder3 天前
Git将本地文件推送到GitHub仓库
git·elasticsearch·github
RocketJ3 天前
mac电脑.sh文件,用来清除git当前分支
git·elasticsearch·macos
Elastic 中国社区官方博客3 天前
JavaScript 中的 ES|QL:利用 Apache Arrow 工具
大数据·开发语言·javascript·elasticsearch·搜索引擎·全文检索·apache
猕员桃3 天前
《Elasticsearch 分布式搜索在聊天记录检索中的深度优化》
分布式·elasticsearch·wpf
追随远方3 天前
Android OpenSL ES 音频播放完整实现指南
android·elasticsearch·音视频
G皮T4 天前
【Elasticsearch】正排索引、倒排索引(含实战案例)
大数据·elasticsearch·搜索引擎·kibana·倒排索引·搜索·正排索引