# Getting aggregations data / paginations on aggregation results

**URL:** https://discuss.elastic.co/t/getting-aggregations-data-paginations-on-aggregation-results/53230
**Category:** Elasticsearch
**Created:** [June 19, 2016, 10:22am UTC](https://discuss.elastic.co/t/getting-aggregations-data-paginations-on-aggregation-results/53230 "2016-06-19T10:22:45Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![ugolas](https://avatars.discourse-cdn.com/v4/letter/u/7993a0/32.png) [@ugolas](https://discuss.elastic.co/u/ugolas)
#### Post date: [June 19, 2016, 10:22am UTC](https://discuss.elastic.co/t/getting-aggregations-data-paginations-on-aggregation-results/53230/1 "2016-06-19T10:22:45Z")

</div>

Hi,  
We have a lot of records and a lot of duplicates in the our storage.

I need to search and return results without duplicates, so I wrote a query which does an aggregation on a specific term, and returns one record per bucket so in my bucket results we have no duplications.

Is there a way to add an aggregation to get facets values for additional terms - but only for the bucket results?

**My example:**  
lets say I have these docs:  
{  
"id": 123,  
"type": "Good",  
"timestamp": 12345  
}, {  
"id": 123,  
"type": "Bad",  
"timestamp": 12346  
}, {  
"id": 125,  
"type": "Bad",  
"timestamp": 12347  
}, {  
"id": 126,  
"type": "Good",  
"timestamp": 12348  
}

After an aggregation on 'id' and sorting by 'timestamp' desc to eliminate duplicates i get 3 buckets with the records:  
'id': 123, 'type': "Bad"  
'id': 125, 'type': "Bad"  
'id': 126, 'type': "Good"

And I need to get the data:  
'type': "Good", 'doc\_count': 1, 'type': "Bad", 'doc\_count': 2.

Also is it possible to apply pagination on the aggregations buckets?

Thanks!

---

<div class="post-metadata">

### Author: ![mainec](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mainec/32/5557_2.png) [@mainec](https://discuss.elastic.co/u/mainec)
#### Post date: [June 20, 2016, 8:13am UTC](https://discuss.elastic.co/t/getting-aggregations-data-paginations-on-aggregation-results/53230/2 "2016-06-20T08:13:34Z")

</div>

> [@ugolas](#):
>
> Also is it possible to apply pagination on the aggregations buckets?

To my knowledge not yet. Check [https://github.com/elastic/elasticsearch/issues/4915](https://github.com/elastic/elasticsearch/issues/4915) for details.

Hope this helps,  
Isabel

---

<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: [July 5, 2017, 10:42pm UTC](https://discuss.elastic.co/t/getting-aggregations-data-paginations-on-aggregation-results/53230/3 "2017-07-05T22:42:24Z")

</div>


