Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ElasticSearch - null nested aggregation #9745

Closed
spvemm opened this issue Feb 18, 2015 · 1 comment
Closed

ElasticSearch - null nested aggregation #9745

spvemm opened this issue Feb 18, 2015 · 1 comment

Comments

@spvemm
Copy link

spvemm commented Feb 18, 2015

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
}
}

@clintongormley
Copy link
Contributor

Hi @spvemm

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.

You need to handle nulls on the application side.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants