# Multi search API with multi indexes

**URL:** <https://discuss.elastic.co/t/multi-search-api-with-multi-indexes/12982>\
**Category:** Elasticsearch\
**Created:** [July 29, 2013, 10:03am UTC](https://discuss.elastic.co/t/multi-search-api-with-multi-indexes/12982 "2013-07-29T10:03:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![oreno](https://avatars.discourse-cdn.com/v4/letter/o/b4bc9f/32.png) [@oreno](https://discuss.elastic.co/u/oreno)\
**Post date:** [July 29, 2013, 10:03am UTC](https://discuss.elastic.co/t/multi-search-api-with-multi-indexes/12982/1 "2013-07-29T10:03:30Z")

</div>

Hi I'm trying to run a multi request using the java api.  
I have 2 queries which I would like to run them both on 2 different indexes. the problem is that apparently I'm unable to direct queries to different indexes as the multi search api suggests here:  
[http://www.elasticsearch.org/guide/reference/api/multi-search/](http://www.elasticsearch.org/guide/reference/api/multi-search/)

When trying to run the queries I actually get result for query running the search on both indexes together...

when I use client.prepareSearch("index1", "index2") it just makes the queries search both indexes at the same time, resulting in getting overload of results.

Also tried putting putHeader("index", "index1") for the request before adding the request to the multi object, but it looks like it ignores it.

did any one ever add this problem before?

Thanks in advanced,

Oren

---

<div class="post-metadata">

**Author:** ![Christian\_Th](https://avatars.discourse-cdn.com/v4/letter/c/f14d63/32.png) [@Christian\_Th](https://discuss.elastic.co/u/Christian_Th)\
**Post date:** [July 29, 2013, 10:33am UTC](https://discuss.elastic.co/t/multi-search-api-with-multi-indexes/12982/2 "2013-07-29T10:33:18Z")

</div>

Hi,  
can you try client.prepareMultiSearch().add(...) and see if this is what  
you want ?

Greetings Christian

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![oreno](https://avatars.discourse-cdn.com/v4/letter/o/b4bc9f/32.png) [@oreno](https://discuss.elastic.co/u/oreno)\
**Post date:** [July 29, 2013, 1:26pm UTC](https://discuss.elastic.co/t/multi-search-api-with-multi-indexes/12982/3 "2013-07-29T13:26:40Z")

</div>

Thanks! that did the trick!

I'm not sure what's the difference between creating the multi object as:  
MultiSearchRequestBuilder multi =new  
MultiSearchRequestBuilder(ProfileReportRequestHandler.getClient());  
or as:  
MultiSearchRequestBuilder multi =  
ProfileReportRequestHandler.getClient().prepareMultiSearch();

but only the second one executed the requests to the exact index that I  
specified on request creation.

thanks again.

On Mon, Jul 29, 2013 at 1:34 PM, Christian Th. [via Elasticsearch Users] \<  
[ml-node+s115913n4038803h28@n3.nabble.com](mailto:ml-node+s115913n4038803h28@n3.nabble.com)\> wrote:

> Hi,  
> can you try client.prepareMultiSearch().add(...) and see if this is what  
> you want ?
> 
> Greetings Christian
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [hidden email][http://user/SendEmail.jtp?type=node&node=4038803&i=0](http://user/SendEmail.jtp?type=node&node=4038803&i=0)  
> .  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> 
> * * *
> 
> If you reply to this email, your message will be added to the discussion  
> below:
> 
> [http://elasticsearch-users.115913.n3.nabble.com/Multi-search-API-with-multi-indexes-tp4038799p4038803.html](http://elasticsearch-users.115913.n3.nabble.com/Multi-search-API-with-multi-indexes-tp4038799p4038803.html)  
> To unsubscribe from Multi search API with multi indexes, click here[http://elasticsearch-users.115913.n3.nabble.com/template/NamlServlet.jtp?macro=unsubscribe\_by\_code&node=4038799&code=b3Jlbm9AZXhlbGF0ZS5jb218NDAzODc5OXw4ODk1Mjk2Nzg=](http://elasticsearch-users.115913.n3.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=4038799&code=b3Jlbm9AZXhlbGF0ZS5jb218NDAzODc5OXw4ODk1Mjk2Nzg=)  
> .  
> NAML[http://elasticsearch-users.115913.n3.nabble.com/template/NamlServlet.jtp?macro=macro\_viewer&id=instant\_html!nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify\_subscribers!nabble%3Aemail.naml-instant\_emails!nabble%3Aemail.naml-send\_instant\_email!nabble%3Aemail.naml](http://elasticsearch-users.115913.n3.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml)

signature.bmp (1M) [http://elasticsearch-users.115913.n3.nabble.com/attachment/4038811/0/signature.bmp](http://elasticsearch-users.115913.n3.nabble.com/attachment/4038811/0/signature.bmp)

---

<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, 2:24am UTC](https://discuss.elastic.co/t/multi-search-api-with-multi-indexes/12982/4 "2017-07-06T02:24:01Z")

</div>


