# Ability to search ES based on the result of previous search in the query

**URL:** <https://discuss.elastic.co/t/ability-to-search-es-based-on-the-result-of-previous-search-in-the-query/312093>\
**Category:** Elasticsearch\
**Created:** [August 15, 2022, 11:32am UTC](https://discuss.elastic.co/t/ability-to-search-es-based-on-the-result-of-previous-search-in-the-query/312093 "2022-08-15T11:32:17Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ananya\_Chowdhury](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ananya_chowdhury/32/98119_2.png) [@Ananya\_Chowdhury](https://discuss.elastic.co/u/Ananya_Chowdhury)\
**Post date:** [August 15, 2022, 11:32am UTC](https://discuss.elastic.co/t/ability-to-search-es-based-on-the-result-of-previous-search-in-the-query/312093/1 "2022-08-15T11:32:17Z")

</div>

Hi,

We want to build a query which will search for a particular string and then it will perform a search based on the result that we have received from previous result.

Can any one help us how we can achieve this. How we can write such elastic query.

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [August 16, 2022, 2:56am UTC](https://discuss.elastic.co/t/ability-to-search-es-based-on-the-result-of-previous-search-in-the-query/312093/2 "2022-08-16T02:56:46Z")

</div>

Welcome to our community! 😃

There is no such query in Elasticsearch, it's something you need to build in your own code.

---

<div class="post-metadata">

**Author:** ![Ananya\_Chowdhury](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ananya_chowdhury/32/98119_2.png) [@Ananya\_Chowdhury](https://discuss.elastic.co/u/Ananya_Chowdhury)\
**Post date:** [August 16, 2022, 8:08am UTC](https://discuss.elastic.co/t/ability-to-search-es-based-on-the-result-of-previous-search-in-the-query/312093/3 "2022-08-16T08:08:22Z")

</div>

> [@warkolm](#):
>
> Elasticsearch, it's something you need to build in your own code

Can you let me know how can we build such query

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [August 16, 2022, 8:09am UTC](https://discuss.elastic.co/t/ability-to-search-es-based-on-the-result-of-previous-search-in-the-query/312093/4 "2022-08-16T08:09:05Z")

</div>

You run one query in your code, collect and parse the results, then pass that to the second query.

---

<div class="post-metadata">

**Author:** ![Ananya\_Chowdhury](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ananya_chowdhury/32/98119_2.png) [@Ananya\_Chowdhury](https://discuss.elastic.co/u/Ananya_Chowdhury)\
**Post date:** [August 16, 2022, 8:36am UTC](https://discuss.elastic.co/t/ability-to-search-es-based-on-the-result-of-previous-search-in-the-query/312093/5 "2022-08-16T08:36:14Z")

</div>

> [@warkolm](#):
>
> one query in your code

We can used Python, but is there any way of doing it in elastic query from the UI. And also is there any way to achieve this using transform input chained data

---

<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:** [September 13, 2022, 8:37am UTC](https://discuss.elastic.co/t/ability-to-search-es-based-on-the-result-of-previous-search-in-the-query/312093/6 "2022-09-13T08:37:01Z")

</div>

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