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
      }
    }
  }
}
相关推荐
斯特凡今天也很帅11 小时前
Elasticsearch数据库专栏(一)Kinaba的基础使用
elasticsearch·kibana
不爱吃糖的程序媛18 小时前
鸿蒙三方库适配读懂 `thirdparty/AES/.gitignore`:哪些文件不该进 Git?
git·elasticsearch·harmonyos
A__tao18 小时前
一键实现 SQL → ES Mapping 转换,支持自定义 `text` 为 `json` 转换
sql·elasticsearch·json
ShawnLiaoking1 天前
pycharm 上传更新代码
ide·elasticsearch·pycharm
果粒蹬i1 天前
Elasticsearch 单机部署实测:安装流程、常见坑点与远程访问配置
大数据·elasticsearch·搜索引擎
AC赳赳老秦1 天前
OpenClaw数据库高效操作指南:MySQL/PostgreSQL批量处理与数据迁移实战
大数据·数据库·mysql·elasticsearch·postgresql·deepseek·openclaw
历程里程碑1 天前
二叉树---二叉树的中序遍历
java·大数据·开发语言·elasticsearch·链表·搜索引擎·lua
Elastic 中国社区官方博客1 天前
使用 Elasticsearch + Jina embeddings 进行无监督文档聚类
大数据·人工智能·elasticsearch·搜索引擎·全文检索·jina
ACGkaka_2 天前
ES 学习(九)从文本到词元:分词器如何“拆解“你的数据
大数据·学习·elasticsearch
Elastic 中国社区官方博客2 天前
如何使用 LogsDB 降低 Elasticsearch 日志存储成本
大数据·运维·数据库·elasticsearch·搜索引擎·全文检索·可用性测试