问:bucket_selector有什么特点?
答:
问:bucket_selector如何使用?
答:
DELETE /bucket_selector_test PUT /bucket_selector_test { "mappings": { "properties": { "type": {"type": "integer"}, "num": {"type": "integer"}, "date": {"type": "date"} } } } POST /bucket_selector_test/_bulk {"index": {"_id": 1}} {"type": 1, "num": 3, "date": "1989-01-10"} {"index": {"_id": 2}} {"type": 2, "num": 7, "date": "1989-01-10"} {"index": {"_id": 3}} {"type": 1, "num": 5, "date": "1990-01-10"} {"index": {"_id": 4}} {"type": 2, "num": 9, "date": "1990-01-10"} {"index": {"_id": 5}} {"type": 1, "num": 6, "date": "1989-01-10"} GET /bucket_selector_test/_search { "size": 0, "aggs": { "selector_aggs": { "date_histogram": { "field": "date", "calendar_interval": "year" }, "aggs": { "sum_aggs": { "sum": { "field": "num" } }, "type_2_aggs": { "filter": { "term": { "type": 2 } }, "aggs": { "sum_aggs": { "sum": { "field": "num" } } } }, "script_aggs": { "bucket_selector": { "buckets_path": { "path1": "sum_aggs", "path2": "type_2_aggs>sum_aggs" }, "script": "params.path2 / params.path1 * 100 > 60" } } } } } } # 结果 { "took" : 10, "timed_out" : false, "_shards" : { "total" : 1, "successful" : 1, "skipped" : 0, "failed" : 0 }, "hits" : { "total" : { "value" : 5, "relation" : "eq" }, "max_score" : null, "hits" : [ ] }, "aggregations" : { "selector_aggs" : { "buckets" : [ { "key_as_string" : "1990-01-01T00:00:00.000Z", "key" : 631152000000, "doc_count" : 2, "type_2_aggs" : { "doc_count" : 1, "sum_aggs" : { "value" : 9.0 } }, "sum_aggs" : { "value" : 14.0 } } ] } } }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)