# Fast Multiple Id Query

**URL:** https://discuss.elastic.co/t/fast-multiple-id-query/3991
**Category:** Elasticsearch
**Created:** [February 27, 2011, 12:50pm UTC](https://discuss.elastic.co/t/fast-multiple-id-query/3991 "2011-02-27T12:50:44Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![davrob](https://avatars.discourse-cdn.com/v4/letter/d/d78d45/32.png) [@davrob](https://discuss.elastic.co/u/davrob)
#### Post date: [February 27, 2011, 12:50pm UTC](https://discuss.elastic.co/t/fast-multiple-id-query/3991/1 "2011-02-27T12:50:44Z")

</div>

Hi,

I want to create a Join index that will hold the relationship between  
two other indexes' ids. In order for this to work I will need to do a  
query that does the following, very quickly using the Java API, once I  
have a list of Ids that I want to turn into JSON:

```
   "results for index <indexname> where index id IN

```

(1,4,5,8,...... 100s or 1000s of ids)"

I could do a bulk query with hundreds of separate id queries or  
iterate through each Id separately, but that would be very  
inefficient. Any ideas to do this efficiently appreciated.

Best Regards,

David.

---

<div class="post-metadata">

### Author: ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)
#### Post date: [February 27, 2011, 7:29pm UTC](https://discuss.elastic.co/t/fast-multiple-id-query/3991/2 "2011-02-27T19:29:59Z")

</div>

You can use the async API to load the ids in parallel. There will be a bulk get API in the near future that will try and optimize that. Note, make sure there is enough mem both on the ES servers and on your client to handle 1000s of json representations.  
On Sunday, February 27, 2011 at 2:50 PM, davrob2 wrote:

> Hi,
> 
> I want to create a Join index that will hold the relationship between  
> two other indexes' ids. In order for this to work I will need to do a  
> query that does the following, very quickly using the Java API, once I  
> have a list of Ids that I want to turn into JSON:
> 
> "results for index where index id IN  
> (1,4,5,8,...... 100s or 1000s of ids)"
> 
> I could do a bulk query with hundreds of separate id queries or  
> iterate through each Id separately, but that would be very  
> inefficient. Any ideas to do this efficiently appreciated.
> 
> Best Regards,
> 
> David.

---

<div class="post-metadata">

### Author: ![Karussell1](https://avatars.discourse-cdn.com/v4/letter/k/50afbb/32.png) [@Karussell1](https://discuss.elastic.co/u/Karussell1)
#### Post date: [March 1, 2011, 8:05pm UTC](https://discuss.elastic.co/t/fast-multiple-id-query/3991/3 "2011-03-01T20:05:28Z")

</div>

why not do a terms query against the special "\_id" field?  
I'm using that one with success 🙂

Regards,  
Peter.

On 27 Feb., 20:29, Shay Banon [shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) wrote:

> You can use the async API to load the ids in parallel. There will be a bulk get API in the near future that will try and optimize that. Note, make sure there is enough mem both on the ES servers and on your client to handle 1000s of json representations.
> 
> On Sunday, February 27, 2011 at 2:50 PM, davrob2 wrote:
> 
> > Hi,
> 
> > I want to create a Join index that will hold the relationship between  
> > two other indexes' ids. In order for this to work I will need to do a  
> > query that does the following, very quickly using the Java API, once I  
> > have a list of Ids that I want to turn into JSON:
> 
> > "results for index where index id IN  
> > (1,4,5,8,...... 100s or 1000s of ids)"
> 
> > I could do a bulk query with hundreds of separate id queries or  
> > iterate through each Id separately, but that would be very  
> > inefficient. Any ideas to do this efficiently appreciated.
> 
> > Best Regards,
> 
> > David.

---

<div class="post-metadata">

### Author: ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)
#### Post date: [March 1, 2011, 10:01pm UTC](https://discuss.elastic.co/t/fast-multiple-id-query/3991/4 "2011-03-01T22:01:34Z")

</div>

Yes, thats certainly possible as well. A multi get API can be a bit more optimized than that (but not much, especially if you use query\_and\_fetch search type).  
On Tuesday, March 1, 2011 at 10:05 PM, Karussell wrote:

> why not do a terms query against the special "\_id" field?  
> I'm using that one with success 🙂
> 
> Regards,  
> Peter.
> 
> On 27 Feb., 20:29, Shay Banon [shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) wrote:
> 
> > You can use the async API to load the ids in parallel. There will be a bulk get API in the near future that will try and optimize that. Note, make sure there is enough mem both on the ES servers and on your client to handle 1000s of json representations.
> > 
> > On Sunday, February 27, 2011 at 2:50 PM, davrob2 wrote:
> > 
> > > Hi,
> > 
> > > I want to create a Join index that will hold the relationship between  
> > > two other indexes' ids. In order for this to work I will need to do a  
> > > query that does the following, very quickly using the Java API, once I  
> > > have a list of Ids that I want to turn into JSON:
> > 
> > > "results for index where index id IN  
> > > (1,4,5,8,...... 100s or 1000s of ids)"
> > 
> > > I could do a bulk query with hundreds of separate id queries or  
> > > iterate through each Id separately, but that would be very  
> > > inefficient. Any ideas to do this efficiently appreciated.
> > 
> > > Best Regards,
> > 
> > > David.

---

<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, 4:11am UTC](https://discuss.elastic.co/t/fast-multiple-id-query/3991/5 "2017-07-06T04:11:09Z")

</div>


