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
      }
    }
  }
}
相关推荐
Aubrey-J1 小时前
Linux中快速部署Elasticsearch(基础&TLS配置)
linux·服务器·elasticsearch
Elasticsearch2 小时前
Elasticsearch:创建一个定制的 DeepSeek 嵌入推理端点
elasticsearch
风清再凯4 小时前
02_ES索引规范&kibana
大数据·elasticsearch·搜索引擎
失散137 小时前
分布式专题——46 ElasticSearch高级查询语法Query DSL实战
java·分布式·elasticsearch·架构
Elasticsearch8 小时前
Elasticsearch 推理 API 增加了开放的可定制服务
elasticsearch
麦麦麦造15 小时前
小小 Postgres,何以替代 Redis、MongoDB 甚至 ES?
redis·mongodb·elasticsearch·postgresql
Zzz 小生15 小时前
Claude Code学习笔记(四)-助你快速搭建首个Python项目
大数据·数据库·elasticsearch
斯普信专业组19 小时前
使用Reindex迁移Elasticsearch集群数据详解(下)
大数据·elasticsearch
JAVA学习通1 天前
OJ竞赛平台----C端题目列表
java·开发语言·jvm·vue.js·elasticsearch
Elasticsearch1 天前
根据用户行为数据中的判断列表在 Elasticsearch 中训练 LTR 模型
elasticsearch