# How to get document ids alongs with aggregation result

**URL:** <https://discuss.elastic.co/t/how-to-get-document-ids-alongs-with-aggregation-result/141450>\
**Category:** Elasticsearch\
**Created:** [July 24, 2018, 9:37pm UTC](https://discuss.elastic.co/t/how-to-get-document-ids-alongs-with-aggregation-result/141450 "2018-07-24T21:37:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![cool\_arun](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cool_arun/32/70465_2.png) [@cool\_arun](https://discuss.elastic.co/u/cool_arun)\
**Post date:** [July 24, 2018, 9:37pm UTC](https://discuss.elastic.co/t/how-to-get-document-ids-alongs-with-aggregation-result/141450/1 "2018-07-24T21:37:12Z")

</div>

I perfom term aggregation on elasticsearch documents that gives me the keyword and its doc count, but i also want all the id of those document that keyword belongs to. How to get that. For example

```
  Key: "ice cream",
  doc_count: 3

```

But what i want this

```
  Key: "ice cream",
  doc_count: 3,
  doc_ids: [1, 2, 3]
```

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [July 24, 2018, 10:08pm UTC](https://discuss.elastic.co/t/how-to-get-document-ids-alongs-with-aggregation-result/141450/2 "2018-07-24T22:08:21Z")

</div>

I think you are looking for: [https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-top-hits-aggregation.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-top-hits-aggregation.html)

---

<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:** [August 21, 2018, 10:08pm UTC](https://discuss.elastic.co/t/how-to-get-document-ids-alongs-with-aggregation-result/141450/3 "2018-08-21T22:08:25Z")

</div>

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