2016-05-28 5 views
3
{ 
    "size": 0, 
    "aggs": { 
     "categories_agg": { 
      "terms": { 
       "field": "categories", 
       "order": { 
        "_count": "desc" 
       } 
      } 
     } 
    } 
} 

特定のフィールドで集計を得るために、私は上記のクエリを使用しました。これは、正常に動作し、同じような結果を与える:用語集のdoc_countの範囲フィルタ

{ 
    "took": 10, 
    "timed_out": false, 
    "_shards": { 
    "total": 5, 
    "successful": 5, 
    "failed": 0 
    }, 
    "hits": { 
    "total": 77445, 
    "max_score": 0, 
    "hits": [] 
    }, 
    "aggregations": { 
    "categories_agg": { 
     "doc_count_error_upper_bound": 794, 
     "sum_other_doc_count": 148316, 
     "buckets": [ 
     { 
      "key": "Restaurants", 
      "doc_count": 25071 
     }, 
     { 
      "key": "Shopping", 
      "doc_count": 11233 
     }, 
     { 
      "key": "Food", 
      "doc_count": 9250 
     }, 
     { 
      "key": "Beauty & Spas", 
      "doc_count": 6583 
     }, 
     { 
      "key": "Health & Medical", 
      "doc_count": 5121 
     }, 
     { 
      "key": "Nightlife", 
      "doc_count": 5088 
     }, 
     { 
      "key": "Home Services", 
      "doc_count": 4785 
     }, 
     { 
      "key": "Bars", 
      "doc_count": 4328 
     }, 
     { 
      "key": "Automotive", 
      "doc_count": 4208 
     }, 
     { 
      "key": "Local Services", 
      "doc_count": 3468 
     } 
     ] 
    } 
    } 
} 

私は各バケットのdoc_count上の特定の範囲内のバケットを得ることができるような方法で凝集をフィルタリングすることができます方法はありますか?

doc_count用レンジフィルターを使用して、最大で25000で、minは5000私はbuckets_selectorによって問題を解決

{ 
    "took": 10, 
    "timed_out": false, 
    "_shards": { 
    "total": 5, 
    "successful": 5, 
    "failed": 0 
    }, 
    "hits": { 
    "total": 77445, 
    "max_score": 0, 
    "hits": [] 
    }, 
    "aggregations": { 
    "categories_agg": { 
     "doc_count_error_upper_bound": 794, 
     "sum_other_doc_count": 148316, 
     "buckets": [ 
     { 
      "key": "Shopping", 
      "doc_count": 11233 
     }, 
     { 
      "key": "Food", 
      "doc_count": 9250 
     }, 
     { 
      "key": "Beauty & Spas", 
      "doc_count": 6583 
     }, 
     { 
      "key": "Health & Medical", 
      "doc_count": 5121 
     }, 
     { 
      "key": "Nightlife", 
      "doc_count": 5088 
     } 
     ] 
    } 
    } 
} 
+0

私は同じ質問の答えを探しています。あなたはこれを解決することができましたか? – shivg

答えて

1

私に与えるべきです。 スクリプトでカウントをフィルタリングできます。

``` 
"aggs": { 
    "categories_agg": { 
     "terms": { 
     "field": "cel_num", 
     "size": 5000, 
     "min_doc_count":1 
     }, 
     "aggs": { 
     "count_bucket_selector": { 
      "bucket_selector": { 
      "buckets_path": { 
       "count": "_count" 
      }, 
      "script": { 
       "lang":"expression", 
       "inline": "count>5000 && count <10000" 
      } 
      } 
     } 
     } 
    } 
    } 
```