# Searching through every document in ES?

**URL:** <https://discuss.elastic.co/t/searching-through-every-document-in-es/286281>\
**Category:** Elasticsearch\
**Created:** [October 8, 2021, 9:38pm UTC](https://discuss.elastic.co/t/searching-through-every-document-in-es/286281 "2021-10-08T21:38:51Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![bensalerno](https://avatars.discourse-cdn.com/v4/letter/b/9dc877/32.png) [@bensalerno](https://discuss.elastic.co/u/bensalerno)\
**Post date:** [October 8, 2021, 9:38pm UTC](https://discuss.elastic.co/t/searching-through-every-document-in-es/286281/1 "2021-10-08T21:38:51Z")

</div>

My cluster has roughly 300,000 documents in it. Right now, I'm only able to query 10,000 at a time. Is there a way to query through all documents? Or is this bad practice?

Many of search queries are returning 0 results because they do not exist within the first 10,000 results. What is my best option here?

Also, is there a way to return the total number of documents in the cluster? I know it's about 300,000 but I really don't know.

---

<div class="post-metadata">

**Author:** ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)\
**Post date:** [October 8, 2021, 9:55pm UTC](https://discuss.elastic.co/t/searching-through-every-document-in-es/286281/2 "2021-10-08T21:55:04Z")

</div>

Hi @bensalerno

There are a few questions there lets start to sort them out.

First for the Total Number of documents

`GET /_cluster/stats`

Statistics on each Index

`GET _cat/indices/?v`

You can search across billions or trillions of documents in Elasticsearch but results sets may be limited, so I am a bit unclear what you are asking.. certainly you can search across 300K documents.

And you can "page" through many results if needed... see [here](https://www.elastic.co/guide/en/elasticsearch/reference/master/paginate-search-results.html#search-after)

And Aggregations have sometimes have some limitations to the number of documents that are used in calculating the aggregations but I don't think you are asking that.

So let's take a look, Can you show us what your search query looks like? are you using the Query DSL or Discover? and perhaps we can help

---

<div class="post-metadata">

**Author:** ![bensalerno](https://avatars.discourse-cdn.com/v4/letter/b/9dc877/32.png) [@bensalerno](https://discuss.elastic.co/u/bensalerno)\
**Post date:** [October 8, 2021, 10:36pm UTC](https://discuss.elastic.co/t/searching-through-every-document-in-es/286281/3 "2021-10-08T22:36:31Z")

</div>

I am just doing a basic match query. Return docs with field Process that match. However, it only ever returns 10,000 results, never more. And many results show up empty

---

<div class="post-metadata">

**Author:** ![bensalerno](https://avatars.discourse-cdn.com/v4/letter/b/9dc877/32.png) [@bensalerno](https://discuss.elastic.co/u/bensalerno)\
**Post date:** [October 8, 2021, 10:39pm UTC](https://discuss.elastic.co/t/searching-through-every-document-in-es/286281/4 "2021-10-08T22:39:26Z")

</div>

When I try to change the size to return over 10,000 it tells me result window is too large.

---

<div class="post-metadata">

**Author:** ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)\
**Post date:** [October 8, 2021, 10:46pm UTC](https://discuss.elastic.co/t/searching-through-every-document-in-es/286281/5 "2021-10-08T22:46:28Z")

</div>

Can you show your actual query and some of the empty results?

If you want more than 10,000 you will use the paging which I referenced above.

> [@stephenb](#):
>
> And you can "page" through many results if needed... see [here](https://www.elastic.co/guide/en/elasticsearch/reference/master/paginate-search-results.html#search-after)

---

<div class="post-metadata">

**Author:** ![bensalerno](https://avatars.discourse-cdn.com/v4/letter/b/9dc877/32.png) [@bensalerno](https://discuss.elastic.co/u/bensalerno)\
**Post date:** [October 8, 2021, 11:10pm UTC](https://discuss.elastic.co/t/searching-through-every-document-in-es/286281/6 "2021-10-08T23:10:52Z")

</div>

I don't need more than 10,000 results. If I search for an item, and it does not return, does that mean it does not exist in the index? Does each query search through the entire index?

---

<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:** [October 8, 2021, 11:12pm UTC](https://discuss.elastic.co/t/searching-through-every-document-in-es/286281/7 "2021-10-08T23:12:41Z")

</div>

Add the `track_total_hits` option to your search.

---

<div class="post-metadata">

**Author:** ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)\
**Post date:** [October 8, 2021, 11:13pm UTC](https://discuss.elastic.co/t/searching-through-every-document-in-es/286281/8 "2021-10-08T23:13:56Z")

</div>

> [@bensalerno](#):
>
> If I search for an item, and it does not return, does that mean it does not exist in the index?

That is correct assuming your query is correctly formed And you are searching across an index or an index pattern that represents the data that you want to search against.

> [@bensalerno](#):
>
> Does each query search through the entire index?

Yes assuming you have not applied filter like a time filter or a range filter or something that limits the search scope.

---

<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:** [November 5, 2021, 11:14pm UTC](https://discuss.elastic.co/t/searching-through-every-document-in-es/286281/9 "2021-11-05T23:14:38Z")

</div>

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