【问题标题】:Aggregation with 0 count Elastic Search计数为 0 的聚合 Elastic Search
【发布时间】:2015-07-21 08:51:40
【问题描述】:

我在弹性索引(id,name,dept,status) 中有一组文档为 {1,pone , d1,m2} {2,ptwo,d1,m2},{3,ptwo,d2,m1} I希望查询按部门获取“m2”状态的结果组。结果集还应包括计数为零的记录,如 {d1:2}、{d2:0}。我们如何使用 Elastic Search aggs 来实现它?

 {
   "query": {
        "match": {
           "status": "m2"
        }
    },
    "aggs" : {
        "results" : {
            "terms" : {
               "field" : "dept"
            }
        }
    }
 }

此查询将不为零计数的“部门”返回为 {d1:2}。此外,我还希望计数为 {d1:2}、{d2:0} 的记录为 0。谢谢

【问题讨论】:

    标签: elasticsearch aggregation


    【解决方案1】:

    您正在寻找的是min_doc_count setting。试试这个:

    {
       "query": {
            "match": {
               "status": "m2"
            }
        },
        "aggs" : {
            "results" : {
                "terms" : {
                   "field" : "dept",
                   "min_doc_count" : 0      <------ add this setting
                }
            }
        }
     }
    

    【讨论】:

    • 能否让投反对票的聪明人解释他为什么这样做是为了所有人的利益?
    • @uriDium 同意!谢谢?
    猜你喜欢
    • 2018-01-14
    • 1970-01-01
    • 2014-06-29
    • 1970-01-01
    • 2021-02-04
    • 2015-09-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多