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
      }
    }
  }
}
相关推荐
Java 码思客9 小时前
【ElasticSearch从入门到架构师】第3章:ES 核心基础概念(架构师必备底层认知)
大数据·elasticsearch·jenkins
徐寿春15 小时前
什么是 Elasticsearch 倒排索引
大数据·elasticsearch·搜索引擎
Java 码思客1 天前
【ElasticSearch从入门到架构师】第1章:ElasticSearch 核心认知与行业定位
大数据·elasticsearch·搜索引擎
serve the people2 天前
Elasticsearch(5) i want to monitor the es health from a http api
大数据·http·elasticsearch
Taerge01102 天前
Doris, StarRocks, ClickHouse, Hologres, ES 对比,选型建议
大数据·clickhouse·elasticsearch
serve the people2 天前
Elasticsearch(1) could you tell me how to use es if i am a beginner
大数据·elasticsearch·jenkins
一个儒雅随和的男子2 天前
Elasticsearch出现深度分页问题怎么解决?
大数据·elasticsearch·搜索引擎
serve the people3 天前
Elasticsearch(3) show me some examples
大数据·elasticsearch·jenkins
是一个Bug3 天前
Elasticsearch 保姆级入门:从“找文件”到“秒级搜索”
大数据·elasticsearch·搜索引擎
serve the people3 天前
Elasticsearch(4) show me some more advanced content
大数据·elasticsearch·jenkins