You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You can't. The agg is null because there were no matching documents. An avg of zero would be incorrect, because it is pretending that it has calculated a real average.
In the below query, if "in_stock_products" returns a "doc_count" of 0, "avg_price" returns a value of "null".
How can one prevent a null value aggregation?
Query:
POST _search/
{
"aggs" :
{
"in_stock_products" :
{
"filter" : {
"range" : {
"stock" : {
"gt" : 0
}
}
},
"aggs" : {
"avg_price" : {
"avg" : {
"field" : "price"
}
}
}
}
}
}
Result:
"in_stock_products": {
"doc_count": 0,
"avg_price": {
"value": null
}
}
The text was updated successfully, but these errors were encountered: