gpt4 book ai didi

elasticsearch - Elasticsearch-查找每个特征的最小值和最大值

转载 作者:行者123 更新时间:2023-12-03 00:38:02 26 4
gpt4 key购买 nike

我有这种格式的数据。

第一数据:

"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_intchar_id的最大值和最小值。我的要求无效:
GET products/_search
{
"size": 0,
"aggs": {
"properties": {
"nested": {
"path": "properties"
},
"aggs": {
"char_ids": {
"terms": {
"field": "properties.char_id",
"size": 10000
},
"min_char_values_int": {
"min": {
"field": "properties.char_value_int"
}
},
"max_char_values_int": {
"max": {
"field": "properties.char_value_int"
}
}
}
}
}
}
}

最佳答案

根据您提供的信息,您似乎没有任何嵌套信息,因此不需要嵌套聚合。

聚合中的简单聚合将适合您的情况。

{
"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
}
}
]
}
}

关于elasticsearch - Elasticsearch-查找每个特征的最小值和最大值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58075277/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com