You can try with a bool query, where you specify how many nested query you need in the must section:
GET test_nested/test/_search
{
"query": {
"bool": {
"must": [
{"nested" : {
"path" : "tags",
"query" : {
"bool" : {
"must" : [
{ "match" : {"tags.key" : "tag1"} }
]
}
}
}},
{"nested" : {
"path" : "tags",
"query" : {
"bool" : {
"must" : [
{ "match" : {"tags.key" : "tag2"} },
{ "match" : {"tags.value" : "val2"} }
]
}
}
}}
]
}
}
}
In this case i have one nested query for selecting all documents with key "tag1" and the second nested query to select all documents with the "tag2" and "value2".
We figured it out. The answer was to create two nested queries, instead of having two clauses to the same nested query.
{
"query":{
"bool":{
"must":[{
"nested":{
"path":"tags",
"query":{
"bool":{
"must":[
{"term":{"tags.name":"name1"}},
{"term":{"tags.value":"value1"}}
]
}
}
}
},
{
"nested":{
"path":"tags",
"query":{
"bool":{
"must":[
{"term":{"tags.name":"name2"}},
{"term":{"tags.value":"value2"}}
]
}
}
}
}]
}
}
}