# Find the intersection of two different types

**URL:** https://discuss.elastic.co/t/find-the-intersection-of-two-different-types/8670
**Category:** Elasticsearch
**Created:** [August 8, 2012, 11:41am UTC](https://discuss.elastic.co/t/find-the-intersection-of-two-different-types/8670 "2012-08-08T11:41:14Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Sergi\_Garces](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sergi_garces/32/2777_2.png) [@Sergi\_Garces](https://discuss.elastic.co/u/Sergi_Garces)
#### Post date: [August 8, 2012, 11:41am UTC](https://discuss.elastic.co/t/find-the-intersection-of-two-different-types/8670/1 "2012-08-08T11:41:14Z")

</div>

Hi,  
I need search in two different types and find the intersection of these two  
types by any field, is there any way to do this without make two queries?

For example, with these queries:

curl -XGET  
'[http://localhost:9200/TEST-1/invoice/\_search?routing=DATA-1-emi](http://localhost:9200/TEST-1/invoice/_search?routing=DATA-1-emi)' -d  
'{"query":{"query\_string":{"query":"itype:(emi)  
content:(stringtosearch)"}}}'  
curl -XGET  
'[http://localhost:9200/TEST-1/invoicefile/\_search?routing=DATA-1-emi](http://localhost:9200/TEST-1/invoicefile/_search?routing=DATA-1-emi)' -d  
'{"query":{"query\_string":{"query":"itype:(emi)  
content:(stringtosearch)"}}}'

The field "content" exists only in the second type, and the itype only in  
the first, but the document id is the same, and I have any other fields  
that can match from one type to other. My problem is that the two types can  
return millions of results, and I can't move it to memory to find the  
intersection. I was thinking about to use a query filter, but it seems that  
the filter query must be against the same type, isn't it?  
I hope I expressed myself well 🙂

---

<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, 3:17am UTC](https://discuss.elastic.co/t/find-the-intersection-of-two-different-types/8670/2 "2017-07-06T03:17:15Z")

</div>


