我正在尝试获取弹性搜索中不包括零的中位数。我有以下查询:call_median 正在从字段call_cnt 获取中位数。但是,我们希望排除 call_cnt 的所有零值。请告诉我如何调整?
{
"query": {
"bool": {
"filter": [
{
"match": {
"abc": "dfffss"
}
},
{
"range": {
"created_time": {
"gte": 1727827200000,
"lte": 1728259200000
}
}
}
]
}
},
"aggs": {
"group_by_label": {
"terms": {
"field": "rate",
"size": 10000
},
"aggs": {
"api_usage": {
"date_histogram": {
"field": "created_time",
"calendar_interval": "week",
"format": "yyyy-MM-dd"
},
"aggs": {
"total_call_sum": {
"sum": {
"field": "call_cnt"
}
},
"call_median": {
"percentiles": {
"field": "call_cnt",
"percents": [50]
}
}
}
}
}
}
}
}
可以用gt(大于)过滤并求和。
,
"aggs": {
"group_by_label": {
"terms": {
"field": "rate",
"size": 10000
},
"aggs": {
"api_usage": {
"date_histogram": {
"field": "created_time",
"calendar_interval": "week",
"format": "yyyy-MM-dd"
},
"aggs": {
"filtered_calls": {
"filter": {
"range": {
"call_cnt": {
"gt": 0
}
}
},
"aggs": {
"call_median": {
"percentiles": {
"field": "call_cnt",
"percents": [50]
}
}
}
},
"total_call_sum": {
"sum": {
"field": "call_cnt"
}
}
}
}
}
}
}