2017-09-05 7 views
0

弾性検索5.5.1を使用しています。私は、各バケット項目の解決策を見つけることができるはずです弾性検索アグリゲーションバケットデータに数学演算を適用する方法

{ 
    "took": 30, 
    "timed_out": false, 
    "_shards": { 
    "total": 5, 
    "successful": 5, 
    "failed": 0 
    }, 
    "hits": { 
    "total": 13, 
    "max_score": 0, 
    "hits": [] 
    }, 
    "aggregations": { 
    "group_by_botId": { 
     "doc_count_error_upper_bound": 0, 
     "sum_other_doc_count": 0, 
     "buckets": [ 
     { 
      "key": 1, 
      "doc_count": 9 
     }, 
     { 
      "key": 3, 
      "doc_count": 4 
     } 
     ] 
    } 
    } 
} 

:データのセットを以下に(doc_count×100/10): 私の要件は、次の式を適用することです。私は、この問題にJava SDKを使用したくないのは、弾性検索REST APIだけを使用するという要件だからです。

答えて

2

あなたは、各バケットのためのスクリプトを実行するためにbucket_script集約を使用することができます。

"aggs": { 
    "group_by_botId": { 
     "terms": { 
     "field": "botId" 
     }, 
     "aggs": { 
     "count": { 
      "bucket_script": { 
      "buckets_path": { 
       "doc_count" : "_count" 
      }, 
      "script": "params.doc_count * 100/10" 
      } 
     } 
     } 
    } 
    } 
関連する問題