Min aggregation issue

If a min aggregation is used inside a terms aggregation, the result doesn't contain any buckets for the terms aggregation, as long as no mapping exists for the min aggregation field (e.g. there is no value for that field and dynamic mapping is used)

Once a mapping for the field exists, the result contains the buckets for the terms aggregation.
The max aggregation works independent of an existing mapping for the field

Use the following shell script to reproduce the issue:

# min aggregation with issue
curl -XDELETE "http://localhost:9200/test"
curl -XPUT "http://localhost:9200/test/_doc/1" -H 'Content-Type: application/json' -d'{ "name": "A", "number": null}' 

# min aggregation with empty result for the terms aggregation
sleep 2
echo 'MIN AGGREGATION WITH EMPTY RESULT'
curl -XGET "http://localhost:9200/test/_search" -H 'Content-Type: application/json' -d'{ "size": 0, "aggs": { "terms": { "terms": { "field": "name.keyword" }, "aggs": { "agg": { "min": { "field": "number" } } } } }}' 

# specify mapping for the number field
curl -XPOST "http://localhost:9200/test/_mapping" -H 'Content-Type: application/json' -d'{ "properties": { "number": { "type": "long" } }}'
sleep 2

# now the result contains buckets for the terms aggregation
echo 'MIN AGGREGATION WITH RESULT'
curl -XGET "http://localhost:9200/test/_search" -H 'Content-Type: application/json' -d'{ "size": 0, "aggs": { "terms": { "terms": { "field": "name.keyword" }, "aggs": { "agg": { "min": { "field": "number" } } } } }}' 

# max aggregation works independet of an existing mapping
curl -XDELETE "http://localhost:9200/test"
curl -XPUT "http://localhost:9200/test/_doc/1" -H 'Content-Type: application/json' -d'{ "name": "A", "number": null}' 

sleep 2
echo 'MAX AGGREGATION WITH RESULT'
curl -XGET "http://localhost:9200/test/_search" -H 'Content-Type: application/json' -d'{ "size": 0, "aggs": { "terms": { "terms": { "field": "name.keyword" }, "aggs": { "agg": { "max": { "field": "number" } } } } }}'

I get the same responses for all the samples. I tested with 7.14.1.

Which Elasticsearch version are you trying this on?

Thanks for the reply.
I'm using 7.12 at the moment. Looks like the issue is solved with 7.14.1...

Looks like the issue was already fixed with 7.13

1 Like

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.