# Collapse over more then 10,000 docs

**URL:** <https://discuss.elastic.co/t/collapse-over-more-then-10-000-docs/308096>\
**Category:** Elasticsearch\
**Created:** [June 24, 2022, 9:42am UTC](https://discuss.elastic.co/t/collapse-over-more-then-10-000-docs/308096 "2022-06-24T09:42:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![LenaM](https://avatars.discourse-cdn.com/v4/letter/l/e79b87/32.png) [@LenaM](https://discuss.elastic.co/u/LenaM)\
**Post date:** [June 24, 2022, 9:42am UTC](https://discuss.elastic.co/t/collapse-over-more-then-10-000-docs/308096/1 "2022-06-24T09:42:11Z")

</div>

I have an index that contains more than 1 million documents. I am using a query with the "collapse" parameter to group a field and get its unique values. Do I get ALL unique values from this field that might match the query, or could some be missing if there are more than 10,000 possible hits for the query due to the default limit of 10,000? How could I make sure to get all possible unique values?

I am new to ES, so I hope my question makes sense.

---

<div class="post-metadata">

**Author:** ![Tomo\_M](https://avatars.discourse-cdn.com/v4/letter/t/848f3c/32.png) [@Tomo\_M](https://discuss.elastic.co/u/Tomo_M)\
**Post date:** [June 26, 2022, 1:43pm UTC](https://discuss.elastic.co/t/collapse-over-more-then-10-000-docs/308096/2 "2022-06-26T13:43:33Z")

</div>

`"collapse"` only collapse the search results and affected by the `size` of query.

First, you can use pagination of the query by [search\_after](https://www.elastic.co/guide/en/elasticsearch/reference/current/collapse-search-results.html#collapsing-with-search-after) (with [PIT](https://www.elastic.co/guide/en/elasticsearch/reference/current/point-in-time-api.html) if necessary).

And as a better way, you may also use terms aggregation. See [Size](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html#search-aggregations-bucket-terms-aggregation-size) section in the doc how to get whole unique terms. Make sure you get `"sum_other_doc_count": 0` to confirm you did not miss any documents.

---

<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 24, 2022, 1:43pm UTC](https://discuss.elastic.co/t/collapse-over-more-then-10-000-docs/308096/3 "2022-07-24T13:43:35Z")

</div>

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