elasticsearch - ElasticSearch-整个文档中的词组匹配?不只是一个特定领域

标签 elasticsearch match quote phrase match-phrase

有什么方法可以在整个文档中使用 flex match_phrase吗?不只是一个特定 Realm 。
我们希望用户能够输入带引号的搜索词,并在文档中的任何位置进行词组匹配。

{
    "size": 20,
    "from": 0,
    "query": {
        "match_phrase": {
            "my_column_name": "I want to search for this exact phrase"
        }
    }
}
目前,我只发现了特定 Realm 的词组匹配。我必须指定字段以在其中进行短语匹配。
我们的文档有数百个字段,因此我认为在每个match_phrase查询中手动输入600多个字段并不可行。生成的JSON将非常庞大。

最佳答案

您可以使用带有类型短语的multi-match query在每个字段上运行match_phrase查询,并使用最佳字段中的_score。参见词组和词组前缀。

If no fields are provided, the multi_match query defaults to the index.query.default_field index settings, which in turn defaults to *. This extracts all fields in the mapping that are eligible to term queries and filters the metadata fields. All extracted fields are then combined to build a query.


添加带有索引数据,搜索查询和搜索结果的工作示例
索引数据:
{
    "name":"John",
    "cost":55,
    "title":"Will Smith"
}
{
    "name":"Will Smith",
    "cost":55,
    "title":"book"
}
搜索查询:
{
  "query": {
    "multi_match": {
      "query": "Will Smith",
      "type": "phrase"
    }
  }
}
搜索结果:
"hits": [
      {
        "_index": "64519840",
        "_type": "_doc",
        "_id": "1",
        "_score": 1.2199391,
        "_source": {
          "name": "Will Smith",
          "cost": 55,
          "title": "book"
        }
      },
      {
        "_index": "64519840",
        "_type": "_doc",
        "_id": "2",
        "_score": 1.2199391,
        "_source": {
          "name": "John",
          "cost": 55,
          "title": "Will Smith"
        }
      }
    ]

关于elasticsearch - ElasticSearch-整个文档中的词组匹配?不只是一个特定领域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64519840/

相关文章:

Elasticsearch 。具有重复值的嵌套字段的术语聚合

Python:删除csv文件中在某个范围内不匹配的所有行

php - 用单引号包裹一个字符串 PHP

ruby-on-rails - Elasticsearch : how to see the indexed data

elasticsearch - 根据 Elasticsearch 中文档的键按优先级过滤

elasticsearch - Elasticsearch 5.1:将其他过滤器应用于 “more like this”查询

objective-c - 通过关键字查找相关音频

Excel - SUMIF 索引和匹配

php - 表中的单引号中的双引号

java字符串用单引号替换反斜杠双引号