# Query for documents presented in different index or type too

**URL:** <https://discuss.elastic.co/t/query-for-documents-presented-in-different-index-or-type-too/81711>\
**Category:** Elasticsearch\
**Created:** [April 9, 2017, 1:30pm UTC](https://discuss.elastic.co/t/query-for-documents-presented-in-different-index-or-type-too/81711 "2017-04-09T13:30:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![boriska70](https://avatars.discourse-cdn.com/v4/letter/b/3bc359/32.png) [@boriska70](https://discuss.elastic.co/u/boriska70)\
**Post date:** [April 9, 2017, 1:30pm UTC](https://discuss.elastic.co/t/query-for-documents-presented-in-different-index-or-type-too/81711/1 "2017-04-09T13:30:29Z")

</div>

Is it possible to fetch a subset of documents of IndexA so that the documents are presented in IndexB too? "Presented in indexB too" means that document.fieldA value of indexA is the same as document.fieldA value of indexB. Or even better, if I can compare by several fields values.

For example,  
if IndexA contains 2 documents: `[{"name":"John", "isManager": true},{"name":"Tim","isManager":false}]`  
and IndexB contains 1 document:`[{"name":"John", "isManager": false}]`  
I want to be able to search over IndexA and get only " **John**" document because it also presented in IndexB. Even more, if possible, I'd prefer to get **nothing** because even John is not exactly the same - it is not marked as "isManager" in indexB.

I'm pretty sure it is not possible to do what I want but asking to be completely sure.  
**Also** is it possible to do this across types in the same index instead of across indices - so that IndexA and IndexB become typeA and typeB?

Thanks in advance for answering.

---

<div class="post-metadata">

**Author:** ![nik9000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nik9000/32/44947_2.png) [@nik9000](https://discuss.elastic.co/u/nik9000)\
**Post date:** [April 9, 2017, 4:36pm UTC](https://discuss.elastic.co/t/query-for-documents-presented-in-different-index-or-type-too/81711/2 "2017-04-09T16:36:47Z")

</div>

Have a look at parent/child and nested documents. There aren't other  
join-like features. Usually the recommendation is to denormalize the data.

---

<div class="post-metadata">

**Author:** ![boriska70](https://avatars.discourse-cdn.com/v4/letter/b/3bc359/32.png) [@boriska70](https://discuss.elastic.co/u/boriska70)\
**Post date:** [April 12, 2017, 9:07am UTC](https://discuss.elastic.co/t/query-for-documents-presented-in-different-index-or-type-too/81711/3 "2017-04-12T09:07:57Z")

</div>

> [@nik9000](#):
>
> parent/child

Thank you for response, Nik.

I want to explain it better - actually I have 2 indices that store similar data coming from 2 absolutely independent sources. Data may come in different time and may not come from one of the sources at all (or come partially). So I have 2 independent, denormalized and self-containing data sets and I need a union between them. There is nothing to denormalize. Building a nested mapping or something like this seems to be not so good approach in my case.

It looks like I cannot do this in a single ES query and need to do this in the code. Just wanted to be sure before I start coding this.

---

<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:** [May 10, 2017, 9:19am UTC](https://discuss.elastic.co/t/query-for-documents-presented-in-different-index-or-type-too/81711/4 "2017-05-10T09:19:01Z")

</div>

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