【问题标题】:Elasticsearch significant terms aggregation doc_count differs from hits when doing a match phrase search for the same termElasticsearch 重要术语聚合 doc_count 在对相同术语进行匹配短语搜索时与命中不同
【发布时间】:2021-05-08 08:58:58
【问题描述】:

我正在使用重要术语聚合,它使用以下查询为我提供了 n 个重要术语及其 doc_count 和 bg_c​​ount:

{
  "query" : {
      "terms" : {"user_id": ["x"]}
  },
  "aggregations" : {
      "word_cloud" : {
          "significant_terms": { 
              "field" : "transcript.results.alternatives.words.word.keyword",
              "size": 200
          }
      }
  },
  "size": 0
}

如果我采用重要术语聚合返回的术语并对该术语进行匹配短语查询。然后我得到的 hits 值与聚合中的 doc_count 不同。

匹配词组查询:

{
  "query": {
    "bool": {
      "must": [
        {
          "match_phrase": {
            "preprocess_data.results.alternatives.transcript": "<term>"
          }
        },
        {
          "match_phrase": {
            "user_id": "x"
          }
        }
      ]
    }
  },
  "from": 0,
  "size": 22
}

字段preprocess_data.results.alternatives.transcript 具有以下映射:

{
    "type" : "text",
    "fields" : {
        "keyword" : {
        "type" : "keyword",
        "ignore_above" : 256
        }
    }
}

在进行聚合和匹配短语搜索时,我无法解释文档计数的差异。请帮忙。

【问题讨论】:

    标签: elasticsearch match-phrase significant-terms


    【解决方案1】:

    这种行为是因为有关doc_count 的数据是从索引的所有分片中获取的,并且在重要术语聚合的情况下,此数据可能是近似值。引用弹性搜索documentation

    有多少文档包含结果中提供的术语的计数 基于对从每个分片返回的样本求和,因此 可能是:

    • 如果某些分片未在其顶部样本中提供给定术语的数据,则为低
    • 考虑背景频率时很高,因为它可能会计算已删除文档中的出现次数

    与大多数设计决策一样,这是权衡的基础,其中 我们选择以牺牲一些代价来提供快速的性能 (通常很小)不准确。但是,大小和分片大小 下一节中介绍的设置提供了帮助控制 准确度等级

    【讨论】:

      猜你喜欢
      • 2015-01-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-21
      • 2014-07-09
      • 2023-01-13
      • 2017-10-27
      • 1970-01-01
      相关资源
      最近更新 更多