【问题标题】:Filter in bucket key and doc_count in elastic search在弹性搜索中过滤桶键和 doc_count
【发布时间】:2019-09-11 09:42:56
【问题描述】:

我有一个包含多个文档的索引。现在我想在弹性搜索中编写一个查询,这将允许我过滤存储桶键和 doc_count

{
  "aggs": {
    "genres": {
      "terms": {
        "field": "event.keyword"
      }
    }
  }
}

"aggregations": {
"genres": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 33,
"buckets": [
{
"key": "eone",
"doc_count": 5
}
,
{
"key": "etwo",
"doc_count": 2
}

]
}
}

我想编写查询,通过它我可以对键名和 dpc 计数应用过滤器。假设我想获得 key 为 eone 且 doc count 为 5 的结果,那么我应该只获得匹配此标准的结果

【问题讨论】:

    标签: elasticsearch


    【解决方案1】:

    您可以尝试使用min_doc_count,如下所示,

    {
        "aggs": {
          "genres": {
            "terms": {
              "field": "event.keyword",
              "min_doc_count": 5
            }
          }
        }
      }
    

    通过使用filtermin_doc_count

    GET index_name/_search
      {
        "size": 0,
        "query": {
          "constant_score": {
            "filter": {
              "bool": {
                "must": [
                  {
                    "match": {
                      "event.keyword": "eone"
                    }
                  }
                ]
              }
            }
          }
        },
        "aggs": {
          "genres": {
            "terms": {
               "field": "event.keyword",
                "min_doc_count": 5
            }
    
          }
        }
      } 
    

    使用includemin_doc_count,如下所示,

    GET index_name/_search
      {
        "size": 0,
        "aggs": {
          "genres": {
            "terms": {
              "field": "event.keyword",
              "min_doc_count": 5,
              "include" : "eone"
            }
          }
        }
      }
    

    查看更多: https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html#_minimum_document_count_4

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-12-30
      • 2012-11-07
      • 1970-01-01
      • 2015-11-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-25
      相关资源
      最近更新 更多