世界上并没有完美的程序,但是我们并不因此而沮丧,因为写程序就是一个不断追求完美的过程。
问:max有什么特点?
答:
问:max如何使用?
答:
DELETE /max_testPUT /max_test
{"mappings": {"properties": {"num_1": {"type": "integer"},"num_2": {"type": "integer"},"histo": {"type": "histogram"}}}
}POST /max_test/_bulk
{"index": {"_id": 1}}
{"num_1": 10, "num_2": 50, "histo": {"values": [1, 2, 3, 4], "counts": [3, 4, 6, 5]}}
{"index": {"_id": 2}}
{"num_1": 20, "num_2": 40, "histo": {"values": [1, 2, 3, 6], "counts": [3, 4, 6, 5]}}
{"index": {"_id": 3}}
{"num_1": 5, "num_2": 60, "histo": {"values": [1, 2, 3, 8], "counts": [3, 4, 6, 5]}}
{"index": {"_id": 4}}
{"num_1": 6, "num_2": 80, "histo": {"values": [1, 2, 3, 5], "counts": [3, 4, 6, 5]}}GET /max_test/_search
{"size": 0,"aggs": {"max_aggs": {"max": {"field": "num_1"}}}
}# 结果
{"took" : 1,"timed_out" : false,"_shards" : {"total" : 1,"successful" : 1,"skipped" : 0,"failed" : 0},"hits" : {"total" : {"value" : 4,"relation" : "eq"},"max_score" : null,"hits" : [ ]},"aggregations" : {"max_aggs" : {"value" : 20.0}}
}GET /max_test/_search
{"size": 0,"aggs": {"max_histo_aggs": {"max": {"field": "histo"}}}
}
# 结果
{"took" : 0,"timed_out" : false,"_shards" : {"total" : 1,"successful" : 1,"skipped" : 0,"failed" : 0},"hits" : {"total" : {"value" : 4,"relation" : "eq"},"max_score" : null,"hits" : [ ]},"aggregations" : {"max_histo_aggs" : {"value" : 8.0}}
}GET /max_test/_search
{"size": 0,"aggs": {"max_num_script_aggs": {"max": {"field": "num_2","script": {"lang": "painless", "source": "_value * params.param","params": {"param": 10}}}}}
}# 结果
{"took" : 1,"timed_out" : false,"_shards" : {"total" : 1,"successful" : 1,"skipped" : 0,"failed" : 0},"hits" : {"total" : {"value" : 4,"relation" : "eq"},"max_score" : null,"hits" : [ ]},"aggregations" : {"max_num_script_aggs" : {"value" : 800.0}}
}