# Metric aggregation fails in composite aggregation

**URL:** https://discuss.elastic.co/t/metric-aggregation-fails-in-composite-aggregation/119933
**Category:** Elasticsearch
**Created:** [February 15, 2018, 7:22am UTC](https://discuss.elastic.co/t/metric-aggregation-fails-in-composite-aggregation/119933 "2018-02-15T07:22:34Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![freedrikp](https://avatars.discourse-cdn.com/v4/letter/f/b4bc9f/32.png) [@freedrikp](https://discuss.elastic.co/u/freedrikp)
#### Post date: [February 15, 2018, 7:22am UTC](https://discuss.elastic.co/t/metric-aggregation-fails-in-composite-aggregation/119933/1 "2018-02-15T07:22:34Z")

</div>

Hi!

I'm using Elasticsearch to store test results of a software. I'm running Elasticsearch on Docker CE with the following configuration:

Docker version 17.12.0-ce, build c97c6d6  
Ubuntu 14.04.5 LTS 14.04 trusty  
[docker.elastic.co/elasticsearch/elasticsearch-oss:6.2.1](http://docker.elastic.co/elasticsearch/elasticsearch-oss:6.2.1)  
[docker.elastic.co/kibana/kibana-oss:6.2.1](http://docker.elastic.co/kibana/kibana-oss:6.2.1)

The documents look like the following:

```
{  
   "product":{  
      "software":{  
         "revision":"251ebc1ed721622f49c5485068f8b39c45005a20",
         "date":"2018-02-09T17:40:34+00:00"
      },
      "os":{  
         "name":"Ubuntu",
         "version":"14.04"
      }
   },
   "results":{  
      "summary":{  
         "Pass":2,
         "Fail":3
      }
   }
}

```

I want to compute the average Pass and Fail numbers for all combinations of os.name and os.version for their newest software version, so I use the following Composite query:

```
GET _search
{
  "size": 0,
    "query": {
      "match_all": {}
    },
    "aggs": {
      "products": {
        "composite": {
          "sources": [
            {
              "osName": {
                "terms": {
                  "field": "product.os.name.keyword"
                }
              }
            },
            {
              "osVer": {
                "terms": {
                  "field": "product.os.version.keyword"
                }
              }
            }
          ]
        },
        "aggs": {
          "revision": {
            "terms": {
              "field": "product.software.revision.keyword",
              "order": {
                "SWDate": "desc"
              },
              "size": 1
            },
            "aggs": {
              "SWDate": {
                "max": {
                  "field": "product.software.date"
                }
              },
               "Pass": {
                "avg": {
                  "field": "results.summary.Pass",
                  "missing": 0
                }
              }
            }
          }
        }
      }
    }
  }

```

However, this fails with:

```
"_shards": {
    "total": 6,
    "successful": 1,
    "skipped": 0,
    "failed": 5,
    "failures": [
      {
        "shard": 0,
        "index": "test_results",
        "node": "<nodeId>",
        "reason": {
          "type": "illegal_state_exception",
          "reason": "Cannot replay yet, collection is not finished: postCollect() has not been called"
        }
      }
    ]
  }

```

If I remove the Pass average aggregation it does not fail but id does fail with other metric aggregations. Any ideas what I might do wrong? Thanks!

---

<div class="post-metadata">

### Author: ![freedrikp](https://avatars.discourse-cdn.com/v4/letter/f/b4bc9f/32.png) [@freedrikp](https://discuss.elastic.co/u/freedrikp)
#### Post date: [February 15, 2018, 11:19am UTC](https://discuss.elastic.co/t/metric-aggregation-fails-in-composite-aggregation/119933/2 "2018-02-15T11:19:09Z")

</div>

It seems that when running elasticsearch 6.1.1 it d seems to work intermittently whereas in 6.2.1 it is fully reproducible.

---

<div class="post-metadata">

### Author: ![freedrikp](https://avatars.discourse-cdn.com/v4/letter/f/b4bc9f/32.png) [@freedrikp](https://discuss.elastic.co/u/freedrikp)
#### Post date: [February 16, 2018, 7:23am UTC](https://discuss.elastic.co/t/metric-aggregation-fails-in-composite-aggregation/119933/3 "2018-02-16T07:23:31Z")

</div>

Created [https://github.com/elastic/elasticsearch/issues/28688](https://github.com/elastic/elasticsearch/issues/28688) for this as I believe it is a bug.

---

<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: [March 16, 2018, 7:24am UTC](https://discuss.elastic.co/t/metric-aggregation-fails-in-composite-aggregation/119933/4 "2018-03-16T07:24:31Z")

</div>

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