# Top-K Plot with nested aggregations

**URL:** <https://discuss.elastic.co/t/top-k-plot-with-nested-aggregations/210662>\
**Category:** Kibana\
**Created:** [December 5, 2019, 9:28am UTC](https://discuss.elastic.co/t/top-k-plot-with-nested-aggregations/210662 "2019-12-05T09:28:18Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![elster](https://avatars.discourse-cdn.com/v4/letter/e/dbc845/32.png) [@elster](https://discuss.elastic.co/u/elster)\
**Post date:** [December 5, 2019, 9:28am UTC](https://discuss.elastic.co/t/top-k-plot-with-nested-aggregations/210662/1 "2019-12-05T09:28:19Z")

</div>

Dear experts,

I would like to create a Top-K Plot as shown [here](https://vega.github.io/vega/examples/top-k-plot/) using this DSL query:

```
"aggs": {
  "nested_app": {
    "nested": {
      "path": "app"
    },
    "aggs": {
      "message" : {
        "filter": {
         "term": {
            "app.key": "contextMap.connectionname"
          }
        },
        "aggs": {
          "login_types": {
            "terms": {
              "field": "app.value_string.raw"
            }
          }
        }
      }
    }
  }
}

```

This is the result I get from Elasticsearch when I send the search request:

```
"aggregations" : {
  "nested_app" : {
    "doc_count" : 2054789105,
    "message" : {
      "doc_count" : 1022033,
      "login_types" : {
        "doc_count_error_upper_bound" : 823,
        "sum_other_doc_count" : 97623,
        "buckets" : [
          {
            "key" : "My Demo Application",
            "doc_count" : 307735
          }
        ]
      }
    }
  }
}

```

Can you please help me integrating the DSL query properly into the data, marks, and sales sections?

The diagram should show the key on the y-axis and the doc\_count on the x-axis.

Thanks and br,  
Elmar

---

<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:** [January 2, 2020, 9:28am UTC](https://discuss.elastic.co/t/top-k-plot-with-nested-aggregations/210662/2 "2020-01-02T09:28:19Z")

</div>

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