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
      }
    }
  }
}
相关推荐
wdfk_prog1 小时前
实战教程:从“对象文件为空“到仓库重生——修复 Git 仓库损坏全记录
大数据·网络·笔记·git·学习·elasticsearch·全文检索
Hello.Reader3 小时前
以 Eland 玩转 Elasticsearch 8.12 Learning-to-Rank
大数据·elasticsearch·jenkins
ALex_zry3 小时前
Git Status 命令深度指南:洞悉仓库状态的核心艺术
大数据·git·elasticsearch
ζั͡山 ั͡有扶苏 ั͡✾3 小时前
Elasticsearch 单节点迁移实战指南:从旧服务器到新环境的完整流程
服务器·elasticsearch·jenkins
ALex_zry14 小时前
Git 乱码文件处理全流程指南:从识别到彻底清除
git·elasticsearch·搜索引擎
Elasticsearch15 小时前
无服务器日志分析由 Elasticsearch 提供支持,推出新的低价层
elasticsearch
麦兜*1 天前
Spring Boot集成方案 + Elasticsearch向量检索,语义搜索核弹
java·spring boot·python·spring·elasticsearch·spring cloud·系统架构
爱学习的小熊猫_1 天前
在Linux上部署RabbitMQ、Redis、ElasticSearch
linux·redis·elasticsearch·中间件·rabbitmq
用手手打人1 天前
SpringCloud -- elasticsearch(二)
大数据·elasticsearch·搜索引擎
nassi_1 天前
Linux 中 Git 操作大全
大数据·elasticsearch·搜索引擎