Collection terminated exception for min aggregation when field is not present in the documents

I am getting collection_terminated_exception when running nested min aggregation. However, max, avg, and sum are returning empty buckets. This is happening when the field we are doing aggregation is not present in any of the documents. I have tested it with ES version 6.7.0 and 6.8.1

Steps to reproduce:

Data:

PUT test
{
  "settings": {
    "number_of_shards": 1,
    "number_of_replicas": 1
  }
}

POST test/_doc/_bulk
{"index":{"_id":"1"}}
{"user_id":"abcd","name":"Jane Doe","score":34.56,"age":45}
{"index":{"_id":"2"}}
{"user_id":"abcd10","name":"John Doe","score":12.34,"age":32}

Query:

GET test/_search
{
  "size": 0,
  "query": {
    "bool": {
      "should": [
        {
          "exists": {
            "field": "marks"
          }
        }
      ]
    }
  },
  "aggregations": {
    "group_by_user_id": {
      "terms": {
        "field": "user_id.keyword",
        "order": [
          {
            "_count": "desc"
          },
          {
            "_key": "asc"
          }
        ]
      },
      "aggregations": {
        "marks_agg": {
          "min": {
            "field": "marks"
          }
        }
      }
    }
  }
}

Response:

{
  "error": {
    "root_cause": [
      {
        "type": "collection_terminated_exception",
        "reason": null
      }
    ],
    "type": "search_phase_execution_exception",
    "reason": "all shards failed",
    "phase": "query",
    "grouped": true,
    "failed_shards": [
      {
        "shard": 0,
        "index": "test",
        "node": "rPmR06ZwS92VNUknAW7Ppw",
        "reason": {
          "type": "collection_terminated_exception",
          "reason": null
        }
      }
    ],
    "caused_by": {
      "type": "collection_terminated_exception",
      "reason": null,
      "caused_by": {
        "type": "collection_terminated_exception",
        "reason": null
      }
    }
  },
  "status": 500
}

Here is the response of avg aggregation. We are observing similar results for max and sum as well:

{
  "took" : 0,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : 0,
    "max_score" : 0.0,
    "hits" : [ ]
  },
  "aggregations" : {
    "group_by_user_id" : {
      "doc_count_error_upper_bound" : 0,
      "sum_other_doc_count" : 0,
      "buckets" : [ ]
    }
  }
}

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