Here is my index mapping:
{
"mappings": {
"properties": {
"non_nested_field": {
"type": "keyword"
},
"nested_field": {
"type": "nested",
"properties": {
"subfield": {
"type": "text"
},
"subfield1": {
"type": "keyword"
},
"subfield2": {
"type": "keyword"
}
}
}
}
}
}
and query:
{
"from": 0,
"size": 0,
"query": {
"bool": {
"should": [
{
"bool": {
"must": [
{
"term": {
"non_nested_field": "value1"
}
},
{
"nested": {
"path": "nested_field",
"query": {
"bool": {
"must": [
{
"term": {
"nested_field.subfield1": "subvalue1"
}
}
]
}
}
}
}
]
}
},
{
"bool": {
"must": [
{
"term": {
"non_nested_field": "value2"
}
},
{
"nested": {
"path": "nested_field",
"query": {
"bool": {
"must": [
{
"term": {
"nested_field.subfield1": "subvalue2"
}
}
]
}
}
}
}
]
}
}
]
}
},
"aggregations": {
"nested_field": {
"nested": {
"path": "nested_field"
},
"aggregations": {
"filter_nested": {
"filter": {
...
},
"aggregations": {
"by_path": {
"terms": {
"shard_min_doc_count": 0,
"field": "nested_field.subfield2",
"show_term_doc_count_error": false,
"min_doc_count": 1,
"order": [
{
"_count": "desc"
},
{
"_key": "asc"
}
]
}
}
}
}
}
}
}
}
The above query combines a nested_field query with a non_nested_query within a bool query.
I would like to learn how to write a nested filter aggregation for the query mentioned above. The nested aggregation appears to only support nested field queries.
My elasticsearch version: 6.8.x