# How to use only the search set generated by the previous query for searching the current query in ElasticSearch

**URL:** <https://discuss.elastic.co/t/how-to-use-only-the-search-set-generated-by-the-previous-query-for-searching-the-current-query-in-elasticsearch/217528>\
**Category:** Elasticsearch\
**Created:** [February 2, 2020, 1:28pm UTC](https://discuss.elastic.co/t/how-to-use-only-the-search-set-generated-by-the-previous-query-for-searching-the-current-query-in-elasticsearch/217528 "2020-02-02T13:28:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![shikjind](https://avatars.discourse-cdn.com/v4/letter/s/5f9b8f/32.png) [@shikjind](https://discuss.elastic.co/u/shikjind)\
**Post date:** [February 2, 2020, 1:28pm UTC](https://discuss.elastic.co/t/how-to-use-only-the-search-set-generated-by-the-previous-query-for-searching-the-current-query-in-elasticsearch/217528/1 "2020-02-02T13:28:07Z")

</div>

I am working on a Search Engine for searching strings. There is around 600 GB of data stored at ElasticSearch index with 4 nodes, having 5 primary shards and 1 replica set.

Assume there is a complete data set A(600GB) on which first time search, results in a new data set B(30GB) and then filters are applied on the data set B.

As of now I am creating a new query every-time a filter is applied and whole data i.e. set A(600GB) is used for searching, I want to know if there is a way to use only the data set B(30GB) for the subsequent filtering. If yes then how can I achieve this.

I am asking this because I think there should some way to achieve this. Since, when I do the search it shows the number of hits, which I think means ElasticSearch knows exactly which documents I want to use for subsequent filtering.

I am new to ElasticSearch and would like to apologize if you find this question trivial.

---

<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:** [February 2, 2020, 3:34pm UTC](https://discuss.elastic.co/t/how-to-use-only-the-search-set-generated-by-the-previous-query-for-searching-the-current-query-in-elasticsearch/217528/2 "2020-02-02T15:34:08Z")

</div>

Welcome !

Just add to the previous query the new filters you want to apply and you'll be all set.

---

<div class="post-metadata">

**Author:** ![shikjind](https://avatars.discourse-cdn.com/v4/letter/s/5f9b8f/32.png) [@shikjind](https://discuss.elastic.co/u/shikjind)\
**Post date:** [February 17, 2020, 9:58am UTC](https://discuss.elastic.co/t/how-to-use-only-the-search-set-generated-by-the-previous-query-for-searching-the-current-query-in-elasticsearch/217528/3 "2020-02-17T09:58:20Z")

</div>

Hi dadoonet,

Thank-you for the response!

Shikhar

---

<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:** [March 16, 2020, 9:58am UTC](https://discuss.elastic.co/t/how-to-use-only-the-search-set-generated-by-the-previous-query-for-searching-the-current-query-in-elasticsearch/217528/4 "2020-03-16T09:58:30Z")

</div>

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