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

**URL:** <https://discuss.elastic.co/t/collection-terminated-exception-for-min-aggregation-when-field-is-not-present-in-the-documents/246111>\
**Category:** Elasticsearch\
**Created:** [August 24, 2020, 12:04pm UTC](https://discuss.elastic.co/t/collection-terminated-exception-for-min-aggregation-when-field-is-not-present-in-the-documents/246111 "2020-08-24T12:04:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ahmadimt07](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ahmadimt07/32/10031_2.png) [@ahmadimt07](https://discuss.elastic.co/u/ahmadimt07)\
**Post date:** [August 24, 2020, 12:04pm UTC](https://discuss.elastic.co/t/collection-terminated-exception-for-min-aggregation-when-field-is-not-present-in-the-documents/246111/1 "2020-08-24T12:04:23Z")

</div>

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:_

```auto
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:_

```auto
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:_

```auto
{
  "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:

```auto
{
  "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" : []
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [September 21, 2020, 12:04pm UTC](https://discuss.elastic.co/t/collection-terminated-exception-for-min-aggregation-when-field-is-not-present-in-the-documents/246111/2 "2020-09-21T12:04:27Z")

</div>

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