我的es版本是7.17版本,我想实现按照一个字段值的取值范围进行聚合统计的功能,kibana上的代码如下:
GET /cch_app_charactgroup/_search?q=:
{
"size" : 0,
"aggs" : {
"recognize_types" : {
"range": {
"field" : "policy_duration",
"ranges": [
{"from": 0,"to": 1.0},
{"from": 1.0,"to": 5.0},
{"from": 5,"to": 10.0},
{"from": 10,"to": 15.0},
{"from": 15,"to": 50}
]
}
}
}
}
在kibana上查询到的结果如下:
{
"took" : 3,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 6,
"relation" : "eq"
},
"max_score" : null,
"hits" : [ ]
},
"aggregations" : {
"recognize_types" : {
"buckets" : [
{
"key" : "0.0-1.0",
"from" : 0.0,
"to" : 1.0,
"doc_count" : 6
},
{
"key" : "1.0-5.0",
"from" : 1.0,
"to" : 5.0,
"doc_count" : 0
},
{
"key" : "5.0-10.0",
"from" : 5.0,
"to" : 10.0,
"doc_count" : 0
},
{
"key" : "10.0-15.0",
"from" : 10.0,
"to" : 15.0,
"doc_count" : 0
},
{
"key" : "15.0-50.0",
"from" : 15.0,
"to" : 50.0,
"doc_count" : 0
}
]
}
}
}
我不知道与之对应的javaapi应该怎么写,网上也查不到资料