Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to do a join negative query in ES

I have 2 indexes in my Elasticsearch setup.

  • index_a
  • index_b

index_a has a field location and have about 1000 documents where as index_b has a field city and have about 600 documents.

I want to find out all the locations from index_a that are not in the city field in index_b. What query should I make to achieve the above ?

like image 646
Amyth Avatar asked Oct 19 '22 16:10

Amyth


1 Answers

You perform two queries: select "all necessary info" from index_b, then perform the search on index_a using the "info" from index_b.

Elasticsearch is not able to "join" in any way two indices in a single query, and rather prefers having denormalized data, or use nested or parent-child relationships.

like image 130
Andrei Stefan Avatar answered Oct 23 '22 08:10

Andrei Stefan