Sub Queries In ElasticSearch

Hi,

Is there a way on elasticsearch to do a subquery ? For example select id from index1 where id not in (select id from index2).

Could you show me the equivalent query on ES ?

Best regaards,

This isn't possible unfortunately.

Thank you for you reply :slight_smile:

But the team of elastic search don't plan to offer such functionnality ?

I think it maybe possible, if the node who received the request launch every subquery on parralel, and after that it make combinisation between result.

I faced such needs but unfortunatelly i am obliged to do it with application but it takes much times.

Best regards,

yes you can do with apply two must filter.
for example:-
GET index/type/_search
{
"query": {
"bool": {
"must": [
{
"filtered": {
"filter": {
"or": [
{
"match_phrase": {
"id": "firstidvalue"
}
},
{
"match_phrase": {
"id": "secondidvalue"
}
}
]
}
}
}
],
"must_not": [
{
"filtered": {
"filter": {
"or": [
{
"match_phrase": {
"id": "secondidvalue"
}
}
]
}
}
}
]
}
}
}

it not reply to my needs because we are searching the id into two different index. and your query is done on just one index.

ATM the only way to do something similar is by using I guess parent/child feature but it only works within the same index.

yes that's true, but the need is to identify the document not inserted into the other index. So it's like a compasion between two index and the data inside them.