Hi,
I try to query two different indices with a filter on a specific field.
Lets say I have an index1 and an index2 where both of the indices have a field named name and just index2 have an extra field code.
Lets say I put 3 documents:
PUT index1/index1/1
{
"name" : "kimchy"
}
PUT index2/index2/1
{
"name" : "kimchy",
"code" : "secret"
}
PUT index2/index2/2
{
"name" : "kimchy",
"code" : "notSecret"
}
I would like to find all documents from index1 where name = kimchy and from index2 where name = kimchy and code = secret.
Means document index1/1 and index2/1 should be in the result.
I tried to use filter to filter the code field. But unfortunately I just get document index2/2 because index1 does not have code field and does not match.
GET index1,index2/_search
{
"query": {
"bool": {
"must": [
{
"term": {
"name": "kimchy"
}
}
],
"filter": {
"term": {
"code": "secret"
}
}
}
}
}
Is there a way to achive that?
If you need any additional info, please let me know.
Thanks!