Difference between results of two queries

Hi!
I'm stuck and I really need help. Here is my use case: I would like to perform two queries and get as final result the difference between those two queries based on a specific field.
Let's assume that I have these docs:
{name: A, state: Washington, Age: 18}
{name: B, state: Washington, Age: 26}
{name: A, state: Georgia, Age: 18}
{name: B, state: Texas, Age: 26}
{name: C, state: Washington, Age: 18}

and I would like to do the difference between query 1: docs with state different from Washington and query 2: docs with state = Washington based on the name. I keep all results from query 1 and and the results of query 2 if the name is not present in the results of query 1.
That would give the result:
{name: A, state: Georgia, Age: 18}
{name: B, state: Texas, Age: 26}
{name: C, state: Washington, Age: 18}

Thanks

That sounds like a join, which is not supported within Elasticsearch. You probably need to run 2 queries and use data from the first in the second.

So there is no way to run two different queries, name them and run a third query using the name of the two first queries?
Isn't it possible with scripts?

You would need to create and run the queries from outside Elasticsearch.

Alright. Thanks

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