2017-04-04 54 views
0

我想知道是否有可能檢索不屬於響應文檔的聚合鍵/計數器。我的意思是已經放在sum_other_doc_count字段中的文件。ElasticSearch Multi Aggregation

我對聚集代碼如下:

AggregationBuilder agg = AggregationBuilders.terms("AGG_1").field("field1") 
      .subAggregation(AggregationBuilders.terms("AGG_2").field("field2") 
        .subAggregation(AggregationBuilders.terms("AGG_3").field("field3") 
          .subAggregation(AggregationBuilders.terms("AGG_4").field("field4")))); 

我得上是不響應的一部分AGG_2 5個文件,但我需要他們儘可能多的人。

"AGG_1": { 
    "doc_count_error_upper_bound": 0, 
    "sum_other_doc_count": 0, 
    "buckets": [ 
     { 
      "key": "404", 
      "doc_count": 3506, 
      "AGG_2": { 
       "doc_count_error_upper_bound": 0, 
       "sum_other_doc_count": 0, 
       "buckets": [ 
       { 
        "key": "OK", 
        "doc_count": 1206, 
        "AGG_3": { 
         "doc_count_error_upper_bound": 0, 
         "sum_other_doc_count": 5, 
         "buckets": [ ... 

感謝您的幫助!

回答

0

您可以terms aggregations設置不同的size值指定多少桶每次你想獲得

{ 
    "aggs" : { 
     "AGG_1" : { 
      "terms" : { 
       "field" : "field1", 
       "size" : 20 // override the number of buckets to return 
      } 
     } 
    } 
} 
+0

感謝呢!我會試試這個。 – Cylon

+0

有沒有辦法猜測我們應該放的確切大小?我的意思是,我不知道我會檢索多少數據... – Cylon

+0

似乎不是。作爲一種解決方法,您可以使用'cardinality'聚合來獲取不同值的數量,但即使這個值不能保證精確,https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics -cardinality-aggregation.html – Random