Find the intersection of two different types


(Sergi Garcés) #1

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' -d
'{"query":{"query_string":{"query":"itype:(emi)
content:(stringtosearch)"}}}'
curl -XGET
'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 :slight_smile:


(system) #2