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
      }
    }
  }
}
相关推荐
sysinside3 小时前
Elasticsearch 9.2 发布 - 分布式搜索和分析引擎
大数据·分布式·elasticsearch
会开花的二叉树3 小时前
即时通讯系统核心模块实现
数据库·mysql·elasticsearch
Jinkxs3 小时前
Elasticsearch - 倒排索引的压缩算法 Elasticsearch 如何节省空间
大数据·elasticsearch·搜索引擎
地瓜伯伯3 小时前
SpringBoot项目整合Elasticsearch启动失败的常见错误总结(2)
spring boot·elasticsearch·spring cloud
阿里云大数据AI技术4 小时前
真实案例复盘:从“三套烟囱”到 All in ES,这家企业如何砍掉 40%运维成本?
人工智能·elasticsearch·搜索引擎
Elasticsearch7 小时前
Elastic 即代码:自动化的不只是基础设施
elasticsearch
Dxy12393102168 小时前
如何基于 Elasticsearch 构建亿级相似图片搜索系统
大数据·elasticsearch·搜索引擎
paj12345678911 小时前
elasticsearch 导出数据命令
大数据·elasticsearch·搜索引擎
shaominjin12311 小时前
使用Git自带的SSH协议搭建git服务器
大数据·elasticsearch·搜索引擎
码--到成功11 小时前
elasticsearch同时启动两个冲突问题
大数据·elasticsearch·bisheng