# Searching multiple index types or indexes (limit results by type)

**URL:** <https://discuss.elastic.co/t/searching-multiple-index-types-or-indexes-limit-results-by-type/583>\
**Category:** Elasticsearch\
**Created:** [May 12, 2015, 10:12pm UTC](https://discuss.elastic.co/t/searching-multiple-index-types-or-indexes-limit-results-by-type/583 "2015-05-12T22:12:18Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mgoncharov](https://avatars.discourse-cdn.com/v4/letter/m/e56c9b/32.png) [@mgoncharov](https://discuss.elastic.co/u/mgoncharov)\
**Post date:** [May 12, 2015, 10:12pm UTC](https://discuss.elastic.co/t/searching-multiple-index-types-or-indexes-limit-results-by-type/583/1 "2015-05-12T22:12:18Z")

</div>

I know that there is a way to search multiple indexes/types.

I am wondering is there a way to pass max hits for each index/index type.

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

Thanks

Mikhail

---

<div class="post-metadata">

**Author:** ![Camilo\_Sierra](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/camilo_sierra/32/14397_2.png) [@Camilo\_Sierra](https://discuss.elastic.co/u/Camilo_Sierra)\
**Post date:** [May 13, 2015, 8:04am UTC](https://discuss.elastic.co/t/searching-multiple-index-types-or-indexes-limit-results-by-type/583/2 "2015-05-13T08:04:46Z")

</div>

hello @mgoncharov i had the same question but I have not found how to limit in the same query for eacht type/index, so i finaly use \_msearch, and i had multiple search querys in the same request and each query had a different max hits, different index and type!

[http://www.elastic.co/guide/en/elasticsearch/reference/current/search-multi-search.html](http://www.elastic.co/guide/en/elasticsearch/reference/current/search-multi-search.html)

---

<div class="post-metadata">

**Author:** ![mgoncharov](https://avatars.discourse-cdn.com/v4/letter/m/e56c9b/32.png) [@mgoncharov](https://discuss.elastic.co/u/mgoncharov)\
**Post date:** [May 15, 2015, 6:19am UTC](https://discuss.elastic.co/t/searching-multiple-index-types-or-indexes-limit-results-by-type/583/3 "2015-05-15T06:19:36Z")

</div>

Hi Camilo, thanks a lot for your answer..Ive just tried multi search api but it does not seem to work.

Here's the example:

This query works fine:

POST \_msearch  
{"index" : "apps", "type":"orders"}  
{"query" : {"match\_all" : {}}, "from" : 0, "size" : 5}  
{"index" : "apps", "type":"quotes"}  
{"query" : {"match\_all" : {}}, "from" : 0, "size" : 5}

but this one fails:

POST \_msearch  
{"index" : "apps", "type":"orders"}  
{"query": {"term" : { "ordered\_quantity" : 5 }},  
"from" : 0, "size" : 5},  
{"index" : "apps", "type":"quotes"}  
{"query" : {"match\_all" : {}}, "from" : 0, "size" : 5}

with Json parse error but why ?

Thanks

Mikhail

---

<div class="post-metadata">

**Author:** ![Camilo\_Sierra](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/camilo_sierra/32/14397_2.png) [@Camilo\_Sierra](https://discuss.elastic.co/u/Camilo_Sierra)\
**Post date:** [May 15, 2015, 7:42am UTC](https://discuss.elastic.co/t/searching-multiple-index-types-or-indexes-limit-results-by-type/583/4 "2015-05-15T07:42:34Z")

</div>

> [@mgoncharov](#):
>
> {"query": {"term" : { "ordered\_quantity" : 5 }},  
> "from" : 0, "size" : 5},

Hello @mgoncharov , yes your problems come to this line, in msearch (as \*bulk api) you need to send your request in one line, hear your from and size attribute are in a new line and also in the end of our line you have a comma, you don't need use a comma between lines, \r\n it's enough. that need to be something more like that :

> [@mgoncharov](#):
>
> {"query": {"term" : { "ordered\_quantity" : 5 }}, "from" : 0, "size" : 5}

- [Bulk API | Elasticsearch Guide [8.11] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-bulk.html)

---

<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 6, 2017, 12:13am UTC](https://discuss.elastic.co/t/searching-multiple-index-types-or-indexes-limit-results-by-type/583/5 "2017-07-06T00:13:52Z")

</div>


