世界上并没有完美的程序,但是我们并不因此而沮丧,因为写程序就是一个不断追求完美的过程。
问:percentile_ranks有什么特点?
答:
DELETE /percentile_ranks_testPUT /percentile_ranks_test{ "mappings": { "properties": { "num": {"type": "integer"} } }}POST /percentile_ranks_test/_bulk{"index": {"_id": 1}}{"num": 1}{"index": {"_id": 2}}{"num": 4}{"index": {"_id": 3}}{"num": 8}{"index": {"_id": 4}}{"num": 12}GET /percentile_ranks_test/_search{ "size": 0, "aggs": { "percentile_ranks_test": { "percentile_ranks": { "field": "num", "values": [ 8, 11 ] } } }}# 结果{ "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" : { "percentile_ranks_test" : { "values" : { "8.0" : 62.5, "11.0" : 100.0 } } }}GET /percentile_ranks_test/_search{ "size": 0, "aggs": { "percentile_ranks_test": { "percentile_ranks": { "field": "num", "values": [ 8, 15 ], "script": { "lang": "painless", "source": "doc['num'].value * params.param", "params": { "param": 3 } } } } }}# 结果{ "took" : 2, "timed_out" : false, "_shards" : { "total" : 1, "successful" : 1, "skipped" : 0, "failed" : 0 }, "hits" : { "total" : { "value" : 4, "relation" : "eq" }, "max_score" : null, "hits" : [ ] }, "aggregations" : { "percentile_ranks_test" : { "values" : { "8.0" : 26.190476190476193, "15.0" : 42.85714285714286 } } }}GET /percentile_ranks_test/_search{ "size": 0, "aggs": { "percentile_ranks_test": { "percentile_ranks": { "field": "num", "values": [ 10, 15 ], "hdr": { "number_of_significant_value_digits": 3 } } } }}# 结果{ "took" : 2, "timed_out" : false, "_shards" : { "total" : 1, "successful" : 1, "skipped" : 0, "failed" : 0 }, "hits" : { "total" : { "value" : 4, "relation" : "eq" }, "max_score" : null, "hits" : [ ] }, "aggregations" : { "percentile_ranks_test" : { "values" : { "10.0" : 75.0, "15.0" : 100.0 } } }}