Hello,
I’m running on 6.8 and I’m unable to build a working term aggregation that can return a document matching two different specific value on the same nested field.
My filtering needs to occur on the aggregation itself, not via a query filter or a post filter.
So, let say I have the following index mapping:
PUT nested_test
{
"mappings": {
"doc": {
"properties": {
"name": {
"type": "keyword"
},
"items": {
"type": "nested",
"properties": {
"id": {
"type": "keyword"
}
}
}
}
}
}
}
with the following data:
PUT nested_test/doc/1
{
"name": "john",
"items": [
{
"id": "drawer"
},
{
"id": "desk"
}
]
}
PUT nested_test/doc/2
{
"name": "vlad",
"items": [
{
"id": "carpet"
},
{
"id": "drawer"
}
]
}
I want to retrieve the name of the persons having BOTH a carpet and a drawer through a term aggregations
I tried the following:
POST nested_test/_search
{
"size": 0,
"aggregations": {
"NESTED": {
"nested": {
"path": "items"
},
"aggregations": {
"FILTER1": {
"filter": {
"term": {
"items.id": "carpet"
}
},
"aggregations": {
"FILTER2": {
"filter": {
"term": {
"items.id": "drawer"
}
},
"aggregations": {
"REVERSE_NESTED": {
"reverse_nested": {},
"aggregations": {
"NAME": {
"terms": {
"field": "name",
"size": 10
}
}
}
}
}
}
}
}
}
}
}
}
No result are returned.
It's work well when filtering a single value or using a filter on multiple value as an "OR" condition.
Wondering what I'm doing wrong
Thanks for your help