# Multiple index search

**URL:** <https://discuss.elastic.co/t/multiple-index-search/46494>\
**Category:** Elasticsearch\
**Created:** [April 6, 2016, 8:44am UTC](https://discuss.elastic.co/t/multiple-index-search/46494 "2016-04-06T08:44:01Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![hemantsajnani](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hemantsajnani/32/21741_2.png) [@hemantsajnani](https://discuss.elastic.co/u/hemantsajnani)\
**Post date:** [April 6, 2016, 8:44am UTC](https://discuss.elastic.co/t/multiple-index-search/46494/1 "2016-04-06T08:44:02Z")

</div>

Experts,

I am able to search multiple indexes like -  
[http://elasticsearchbaseurl/shows,movies/all/\_search](http://elasticsearchbaseurl/shows,movies/all/_search)

referring to two indexes - shows and movies.

Question: Is there a way to pass max hits for each index. I want only 2 records to be returned from each index.

We are working on the grouped autocomplete , so would like to be able to make one call and then group results on the index name.

Please help.

Regards,  
Hemant

---

<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:** [April 12, 2016, 6:59am UTC](https://discuss.elastic.co/t/multiple-index-search/46494/2 "2016-04-12T06:59:00Z")

</div>

Hi Hemant,

sounds like you're after the [multi search API](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-multi-search.html).

Daniel

---

<div class="post-metadata">

**Author:** ![hemantsajnani](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hemantsajnani/32/21741_2.png) [@hemantsajnani](https://discuss.elastic.co/u/hemantsajnani)\
**Post date:** [April 21, 2016, 12:05pm UTC](https://discuss.elastic.co/t/multiple-index-search/46494/3 "2016-04-21T12:05:35Z")

</div>

Thanks Daniel; tried this in request body of API-  
{"index" : "shows","type":"all"}  
{"query" : {"match\_all" : {}}, "from" : 0, "size" : 2}  
{"index" : "movies","type":"all"}  
{"query" : {"match\_all" : {}}, "from" : 0, "size" : 2}

We need 2 "shows" and 2 "movies" to be returned but it returns 2 "shows" and not returns "movies" - basically the first index is queried and 2nd one is ignored ("movies" in this example).

Can you, please, share what wrong I am doing here?

Regards,  
Hemant

---

<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:** [April 22, 2016, 12:27pm UTC](https://discuss.elastic.co/t/multiple-index-search/46494/4 "2016-04-22T12:27:23Z")

</div>

Hi Hemant,

Your `_msearch` is fine. In fact, if I enter this example, it returns two movies and two shows:

```auto
DELETE /movies
DELETE /shows

POST /_bulk
{"index":{"_index":"movies","_type":"all"}}
{"title": "Back to the Future I"}
{"index":{"_index":"movies","_type":"all"}}
{"title": "Back to the Future II"}
{"index":{"_index":"movies","_type":"all"}}
{"title": "Back to the Future III"}
{"index":{"_index":"shows","_type":"all"}}
{"title": "Big Bang Theory"}
{"index":{"_index":"shows","_type":"all"}}
{"title": "IT Crowd"}
{"index":{"_index":"shows","_type":"all"}}
{"title": "Dr. Who"}

GET /_msearch
{"index" : "shows","type":"all"}
{"query" : {"match_all" : {}}, "from" : 0, "size" : 2}
{"index" : "movies","type":"all"}
{"query" : {"match_all" : {}}, "from" : 0, "size" : 2}

```

`_msearch` returns a response array. Did you check all responses?

Daniel

---

<div class="post-metadata">

**Author:** ![hemantsajnani](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hemantsajnani/32/21741_2.png) [@hemantsajnani](https://discuss.elastic.co/u/hemantsajnani)\
**Post date:** [May 2, 2016, 10:09am UTC](https://discuss.elastic.co/t/multiple-index-search/46494/5 "2016-05-02T10:09:15Z")

</div>

Thanks Daniel, it is working fine.

Can you, please help with how to apply "wild card" in \_msearch?

{"index" : "shows","type":"all"}  
{"query" : {"match" : {"\_all": "_Future_"}}, "from" : 0, "size" : 2}  
{"index" : "movies","type":"all"}  
{"query" : {"match" : {"\_all": "_Future_"}}, "from" : 0, "size" : 2}  
{"index" : "stars","type":"all"}  
{"query" : {"match" : {"all": "_Future_"}}, "from" : 0, "size" : 2}

how to use the "widcard" option above?

Thanks again for your time and explanation.

Regards,  
Hemant

---

<div class="post-metadata">

**Author:** ![hemantsajnani](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hemantsajnani/32/21741_2.png) [@hemantsajnani](https://discuss.elastic.co/u/hemantsajnani)\
**Post date:** [May 2, 2016, 10:25am UTC](https://discuss.elastic.co/t/multiple-index-search/46494/6 "2016-05-02T10:25:05Z")

</div>

Below is working. Please advise if this is the optimized way or if there is a better way to achieve this

index" : "shows","type":"all"}  
{"query" : {"wildcard" : {"\_all": "_Future_"}}, "from" : 0, "size" : 2}  
{"index" : "movies","type":"all"}  
{"query" : {"wildcard" : {"\_all": "_Future_"}}, "from" : 0, "size" : 2}  
{"index" : "stars","type":"all"}  
{"query" : {"wildcard" : {"title": "_Future_"}}, "from" : 0, "size" : 2}

Regards,  
Hemant

---

<div class="post-metadata">

**Author:** ![codersagar](https://avatars.discourse-cdn.com/v4/letter/c/6f9a4e/32.png) [@codersagar](https://discuss.elastic.co/u/codersagar)\
**Post date:** [March 7, 2017, 10:20am UTC](https://discuss.elastic.co/t/multiple-index-search/46494/7 "2017-03-07T10:20:07Z")

</div>

Hey @hemantsajnani,  
I am having the same problem as you. Only, the index in the first row is being queried. All other indexes are ignored. How it started working for you ? What did you change inside request-body ?

---

<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:02pm UTC](https://discuss.elastic.co/t/multiple-index-search/46494/8 "2017-07-05T22:02:31Z")

</div>


