# Fetching results from ES based on multiple queries

**URL:** <https://discuss.elastic.co/t/fetching-results-from-es-based-on-multiple-queries/54653>\
**Category:** Elasticsearch\
**Created:** [July 4, 2016, 1:24pm UTC](https://discuss.elastic.co/t/fetching-results-from-es-based-on-multiple-queries/54653 "2016-07-04T13:24:37Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![vasanth\_kumar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vasanth_kumar/32/101447_2.png) [@vasanth\_kumar](https://discuss.elastic.co/u/vasanth_kumar)\
**Post date:** [July 4, 2016, 1:24pm UTC](https://discuss.elastic.co/t/fetching-results-from-es-based-on-multiple-queries/54653/1 "2016-07-04T13:24:37Z")

</div>

I've a scenario, where i need to get one value for each search term query,  
For example:  
"must": [

```
    { "match": { "name": "john" }},
    {"match": { "name": "smith" }}
  ]

```

this is an example query, where i need a resultset for each name matching "john"  
and another matching "smith".

So, eventhough if there are more than one result set matches with "john" and "smith", need one result for eachh query.

I am using 1.1.2 version.

---

<div class="post-metadata">

**Author:** ![danielmitterdorfer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/danielmitterdorfer/32/110510_2.png) [@danielmitterdorfer](https://discuss.elastic.co/u/danielmitterdorfer)\
**Post date:** [July 5, 2016, 6:40am UTC](https://discuss.elastic.co/t/fetching-results-from-es-based-on-multiple-queries/54653/2 "2016-07-05T06:40:54Z")

</div>

Hi @vasanth_kumar,

the [msearch API](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-multi-search.html) seems like a good fit if I've understood your requirements correctly.

btw, there is no 1.9 version of Elasticsearch. Did you mean 0.9 or 1.7?

Daniel

---

<div class="post-metadata">

**Author:** ![vasanth\_kumar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vasanth_kumar/32/101447_2.png) [@vasanth\_kumar](https://discuss.elastic.co/u/vasanth_kumar)\
**Post date:** [July 5, 2016, 7:29am UTC](https://discuss.elastic.co/t/fetching-results-from-es-based-on-multiple-queries/54653/3 "2016-07-05T07:29:48Z")

</div>

Thanks @danielmitterdorfer.  
we are using, 1.1.2 version. This serves the need, but lets say my search criteria is dynamic, this solution would be little tricky:worried:

---

<div class="post-metadata">

**Author:** ![danielmitterdorfer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/danielmitterdorfer/32/110510_2.png) [@danielmitterdorfer](https://discuss.elastic.co/u/danielmitterdorfer)\
**Post date:** [July 5, 2016, 7:35am UTC](https://discuss.elastic.co/t/fetching-results-from-es-based-on-multiple-queries/54653/4 "2016-07-05T07:35:47Z")

</div>

Hi @vasanth_kumar,

well, you then need to build the msearch JSON also dynamically. I don't know your client language but in general, you could use the GOF Builder pattern to build your msearch query dynamically.

Daniel

---

<div class="post-metadata">

**Author:** ![vasanth\_kumar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vasanth_kumar/32/101447_2.png) [@vasanth\_kumar](https://discuss.elastic.co/u/vasanth_kumar)\
**Post date:** [July 5, 2016, 7:44am UTC](https://discuss.elastic.co/t/fetching-results-from-es-based-on-multiple-queries/54653/5 "2016-07-05T07:44:42Z")

</div>

Thanks @danielmitterdorfer. I'll try.

---

<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, 10:38pm UTC](https://discuss.elastic.co/t/fetching-results-from-es-based-on-multiple-queries/54653/6 "2017-07-05T22:38:19Z")

</div>


