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
      }
    }
  }
}
相关推荐
risc12345614 小时前
Elasticsearch的shrink为啥不用软链接用硬链接
elasticsearch·lucene
Elasticsearch15 小时前
jina-embeddings-v5-omni:用于文本、图像、音频和视频的 embeddings
elasticsearch
森屿~~16 小时前
CMA-ES:从搜索分布自适应到协方差矩阵学习
学习·elasticsearch·矩阵
剑神一笑16 小时前
Linux tree 命令深度解析:从目录遍历到树形可视化的完整实现
linux·运维·elasticsearch
Lucky me.18 小时前
Cloud code完整命令手册
大数据·elasticsearch·搜索引擎
OYangxf19 小时前
Git Conflict Resolution
大数据·git·elasticsearch
青槿吖19 小时前
第一篇:Elasticsearch 入门踩坑记:从 “URL 拼写错误” 到跑通第一个搜索服务
大数据·elasticsearch·搜索引擎·spring cloud·微服务·架构·全文检索
Elasticsearch20 小时前
Elasticsearch ES|QL “读取时模式”:你的未映射字段一直都在那里
elasticsearch
Elastic 中国社区官方博客20 小时前
一个索引,所有媒体:介绍 jina-embeddings-v5-omni
大数据·人工智能·elasticsearch·搜索引擎·ai·媒体·jina