# Query Sequencing

**URL:** <https://discuss.elastic.co/t/query-sequencing/40938>\
**Category:** Elasticsearch\
**Created:** [February 4, 2016, 7:51am UTC](https://discuss.elastic.co/t/query-sequencing/40938 "2016-02-04T07:51:44Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shiv\_Naidu](https://avatars.discourse-cdn.com/v4/letter/s/e56c9b/32.png) [@Shiv\_Naidu](https://discuss.elastic.co/u/Shiv_Naidu)\
**Post date:** [February 4, 2016, 7:51am UTC](https://discuss.elastic.co/t/query-sequencing/40938/1 "2016-02-04T07:51:44Z")

</div>

Hi All,

I believe this problem is solved before but couldn't find it in google search or in this forum. If my problem can be solved differently please help me to understand that.

I have 4 different queries, Q1, Q2, Q3, Q4. I have to run these queries in sequence based on I get a result for each of the query. The sequence logic goes something like this,

```
result1 = run(Q1);

if ( result1. count == 0 )
{
    result2 = run(Q2);

    if ( result2.count == 0)
   {
      ....
   }

}

```

I checked the boolean query and filters but doesn't quite fit in to what we wanted to do. But I found out that I can run multiple queries in parallel using muti search APIs. I can use that to run it in parallel and check the results but it seems like a overkill.

Hope I am making sense. Please let me know a good solution.

-Shiv

---

<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 5, 2017, 11:18pm UTC](https://discuss.elastic.co/t/query-sequencing/40938/2 "2017-07-05T23:18:52Z")

</div>


