我有这种格式的数据。
第一个数据:
"properties" : [
{
"char_id" : 347,
"char_value_string" : "107",
"char_value_int" : 107
},
{
"char_id" : 906,
"char_value_string" : "8",
"char_value_int" : 8
},
{
"char_id" : 908,
"char_value_string" : "Question_V1",
"char_value_int" : null
}
}
第二个数据:
"properties" : [
{
"char_id" : 347,
"char_value_string" : "110",
"char_value_int" : 110
},
{
"char_id" : 906,
"char_value_string" : "18",
"char_value_int" : 18
},
{
"char_id" : 908,
"char_value_string" : "Question_V2",
"char_value_int" : null
}
}
第三数据:
"properties" : [
{
"char_id" : 347,
"char_value_string" : "220",
"char_value_int" : 220
},
{
"char_id" : 906,
"char_value_string" : "54",
"char_value_int" : 54
},
{
"char_id" : 908,
"char_value_string" : "Question_V3",
"char_value_int" : null
}
}
我需要使用聚合来找到每个char_value_int
的{{1}}的最大值和最小值。我的要求无效:
char_id
答案 0 :(得分:3)
根据您提供的信息,您似乎没有任何嵌套信息,因此您不需要嵌套聚合。
简单的聚合将适合您的情况。
{
"size": 0,
"aggs": {
"char_ids": {
"terms": {
"field": "properties.char_id"
},
"aggs": {
"min_char_values_int": {
"min": {
"field": "properties.char_value_int"
}
},
"max_char_values_int": {
"max": {
"field": "properties.char_value_int"
}
}
}
}
}
}
返回
"aggregations": {
"char_ids": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": 347,
"doc_count": 3,
"min_char_values_int": {
"value": 8
},
"max_char_values_int": {
"value": 220
}
},
{
"key": 906,
"doc_count": 3,
"min_char_values_int": {
"value": 8
},
"max_char_values_int": {
"value": 220
}
},
{
"key": 908,
"doc_count": 3,
"min_char_values_int": {
"value": 8
},
"max_char_values_int": {
"value": 220
}
}
]
}
}