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".
You're almost there, your `nested` query just needs to go inside the `bool/filter` clause:
{
"query": {
"bool": {
"filter": [
{
"term": {
"access_account.nid": 17,
"destroyed_at": null
}
},
{
"nested": {
"path": "categories",
"query": {
"bool": {
"filter": [
{
"terms": {
"categories.id": [
15,
17
]
}
}
]
}
}
}
}
]
}
}
}