# Pipeline Aggregation for pivot on aggregation

**URL:** <https://discuss.elastic.co/t/pipeline-aggregation-for-pivot-on-aggregation/167074>\
**Category:** Elasticsearch\
**Created:** [February 5, 2019, 8:04am UTC](https://discuss.elastic.co/t/pipeline-aggregation-for-pivot-on-aggregation/167074 "2019-02-05T08:04:58Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ShawnClark](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shawnclark/32/40566_2.png) [@ShawnClark](https://discuss.elastic.co/u/ShawnClark)\
**Post date:** [February 5, 2019, 8:04am UTC](https://discuss.elastic.co/t/pipeline-aggregation-for-pivot-on-aggregation/167074/1 "2019-02-05T08:04:58Z")

</div>

Been searching around quite a bit to find a solution to my problem. Hopefully this is possible with ElasticSearch. I have this query:

```
GET _search
{
  "query": {
    "bool": {
      "must": [
        {"exists" : { "field" : "lvl.keyword" }}
      ]
    }
  },
  "size": 0, 
  "aggs": {
    "player": {
      "terms": {
        "field": "id.keyword",
        "size": 10000000
      },
      "aggs": {
        "min-level": {
          "min": {
            "field": "lvl.keyword"
          }
        }
      }
    }
  }
}

```

Which gives a result like:

```
  "aggregations": {
    "player": {
      "doc_count_error_upper_bound": 0,
      "sum_other_doc_count": 0,
      "buckets": [
        {
          "key": "123",
          "doc_count": 24,
          "min-level": {
            "value": 2
          }
        },
        {
          "key": "456",
          "doc_count": 14,
          "min-level": {
            "value": 1
          }
        },
        {
          "key": "678",
          "doc_count": 14,
          "min-level": {
            "value": 1
          }
        },
        {
          "key": "987",
          "doc_count": 12,
          "min-level": {
            "value": 4
          }
        },
        {
          "key": "476",
          "doc_count": 10,
          "min-level": {
            "value": 5
          }
        }
      ]
    }
  }

```

What I need is a pivot on that result so that I can get an output of how many players have the same "min-level".

```
"min-level", "# of players"
1, 2
2, 1
4, 1
5, 1

```

Is that possible with a pipeline aggregation or what are my options to acquire that data from the initial aggregation?

---

<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 5, 2019, 8:05am UTC](https://discuss.elastic.co/t/pipeline-aggregation-for-pivot-on-aggregation/167074/2 "2019-03-05T08:05:00Z")

</div>

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