# Aggregate-on-fields-and-get-distinct-documents

**URL:** <https://discuss.elastic.co/t/aggregate-on-fields-and-get-distinct-documents/186778>\
**Category:** Elasticsearch\
**Created:** [June 20, 2019, 10:32pm UTC](https://discuss.elastic.co/t/aggregate-on-fields-and-get-distinct-documents/186778 "2019-06-20T22:32:27Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rachana\_Maniyar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rachana_maniyar/32/48476_2.png) [@Rachana\_Maniyar](https://discuss.elastic.co/u/Rachana_Maniyar)\
**Post date:** [June 20, 2019, 10:32pm UTC](https://discuss.elastic.co/t/aggregate-on-fields-and-get-distinct-documents/186778/1 "2019-06-20T22:32:27Z")

</div>

Hi, I was going through the following thread that talks about how you could get distinct documents with aggregation terms and top hits.

> [@Aggregate on fields and get distinct documents](https://discuss.elastic.co/t/aggregate-on-fields-and-get-distinct-documents/43902):
>
> So I have three documents: Document 1: Title: Paracetamol Subject: SideEffects Body: "some content" Document 2: Title: Paracetamol Type: SideEffects Body: "some different content" Document 3: Title: Paracetamol Type: IndicationsAndDose Body: "some different content" Is it possible to aggregate the results by Title and Type where subject is equal to SideEffects so that the hit count is equal to two. So the following documents would be returned: Document 1: Title: Paracetamol Subje…

my question is, this will work with typically what size of documents ?

I have some million records and the above query yields me READTimeOut error from elasticsearch.

Is there some other way to address getting unique results for this huge dataset ?

just using aggregation terms to get the list of unique documents works fine for this dataset but I need to access the actual document values and using top\_hits is giving readTimeout error.  
Kindly advise.

Thanks.

---

<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 18, 2019, 10:32pm UTC](https://discuss.elastic.co/t/aggregate-on-fields-and-get-distinct-documents/186778/2 "2019-07-18T22:32:35Z")

</div>

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