# Queries across two distinct indices

**URL:** <https://discuss.elastic.co/t/queries-across-two-distinct-indices/146196>\
**Category:** Elasticsearch\
**Created:** [August 27, 2018, 2:45pm UTC](https://discuss.elastic.co/t/queries-across-two-distinct-indices/146196 "2018-08-27T14:45:25Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mehdi-gital](https://avatars.discourse-cdn.com/v4/letter/m/65b543/32.png) [@mehdi-gital](https://discuss.elastic.co/u/mehdi-gital)\
**Post date:** [August 27, 2018, 2:45pm UTC](https://discuss.elastic.co/t/queries-across-two-distinct-indices/146196/1 "2018-08-27T14:45:26Z")

</div>

Hello,

Let's say I have two indices S (fields: ID, shoe size) and H (fields: ID, height)  
where there's at least one field that runs across the two sides.

Is it possible to run a native elastic query across the two, such as:  
Get the height of everyone whose shoe size = 10.5.

I know I can do this in say a Python wrapper but I'm looking for the simplest  
possible solution.

Thank you!

---

<div class="post-metadata">

**Author:** ![loren](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/loren/32/44942_2.png) [@loren](https://discuss.elastic.co/u/loren)\
**Post date:** [August 27, 2018, 5:01pm UTC](https://discuss.elastic.co/t/queries-across-two-distinct-indices/146196/2 "2018-08-27T17:01:22Z")

</div>

I think you need two ES queries:

1. Get IDs from H where height == 10.5
2. Multi-get records from S using IDs from step 1.

Alternatively, create a new index SH that joins the two indices on ID, and then you can run one ES query on it.

---

<div class="post-metadata">

**Author:** ![mehdi-gital](https://avatars.discourse-cdn.com/v4/letter/m/65b543/32.png) [@mehdi-gital](https://discuss.elastic.co/u/mehdi-gital)\
**Post date:** [August 27, 2018, 6:32pm UTC](https://discuss.elastic.co/t/queries-across-two-distinct-indices/146196/3 "2018-08-27T18:32:39Z")

</div>

Thank you, Loren!

I didn't know about mget but it could definitely be useful.  
Unfortunately, merging the indices won't be an option in my real project though.  
I have three types of indices and I wanna be able to play this game with any combination  
and in any direction and they're of massive sizes ...

---

<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:** [September 24, 2018, 6:32pm UTC](https://discuss.elastic.co/t/queries-across-two-distinct-indices/146196/4 "2018-09-24T18:32:54Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
