世界上并没有完美的程序,但是我们并不因此而沮丧,因为写程序就是一个不断追求完美的过程。
问:boxplot有什么特点?
答:
问:boxplot如何使用?
答:
# 删除
DELETE /boxplot_test
# 映射
PUT /boxplot_test
{
"mappings": {
"properties": {
"name": {"type": "keyword"},
"filter_type": {"type": "keyword"},
"num": {"type": "integer"}
}
}
}
# 索引
POST /boxplot_test/_bulk?routing=1&refresh
{"index": {"_id": 1}}
{"name": "hello", "filter_type": "t1", "num": 3}
{"index": {"_id": 2}}
{"name": "me", "filter_type": "t2", "num": 5}
{"index": {"_id": 3}}
{"name": "me", "filter_type": "t1", "num": 18}
{"index": {"_id": 4}}
{"name": "hello", "filter_type": "t1", "num": 20}
{"index": {"_id": 5}}
{"name": "good", "filter_type": "t1", "num": 28}
{"index": {"_id": 6}}
{"name": "me", "filter_type": "t2", "num": 50}
{"index": {"_id": 7}}
{"name": "good", "filter_type": "t1", "num": 58}
{"index": {"_id": 8}}
{"name": "hello", "filter_type": "t1", "num": 88}
# 搜索
GET /boxplot_test/_search?size=0
{
"aggs": {
"boxplot_aggs": {
"boxplot": {
"field": "num",
"compression": 200
}
}
}
}
# 结果
{
"took" : 1,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 8,
"relation" : "eq"
},
"max_score" : null,
"hits" : [ ]
},
"aggregations" : {
"boxplot_aggs" : {
"min" : 3.0,
"max" : 88.0,
"q1" : 11.5,
"q2" : 24.0,
"q3" : 54.0
}
}
}
# 搜索
GET /boxplot_test/_search?size=0
{
"aggs": {
"boxplot_aggs": {
"boxplot": {
"field": "num",
"script": {
"lang": "painless",
"source": "doc.num.value * params.param",
"params": {
"param": 10
}
}
}
}
}
}
# 结果
{
"took" : 1,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 8,
"relation" : "eq"
},
"max_score" : null,
"hits" : [ ]
},
"aggregations" : {
"boxplot_aggs" : {
"min" : 30.0,
"max" : 880.0,
"q1" : 115.0,
"q2" : 240.0,
"q3" : 540.0
}
}
}



