Hello everyone !
I would like to create filter and aggregations after filter for procuts in Elasticsearch. I am having base aggregations for all products:
"size": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 87,
"buckets": [
{
"key": "6",
"doc_count": 10
},
{
"key": "5,5",
"doc_count": 10
}
]
}
},
"brand": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 87,
"buckets": [
{
"key": "Apple",
"doc_count": 20
},
{
"key": "Samsung",
"doc_count": 10
},
{
"key": "Xiaomi",
"doc_count": 48
},
{
"key": "Huawei",
"doc_count": 33
}
]
}
}
After I make query for one of those brands and size like:
query": {
"bool": {
"filter": [
"term": {
"brand": "Samsung"
},
"term": {
"size": "6"
}
]
}
}
I am getting back aggregations only for filtered brand Samsung.
Actual Result
"size": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 87,
"buckets": [
{
"key": "6",
"doc_count": 3
},
{
"key": "5,5",
"doc_count": 2
}
]
}
},
"brand": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 87,
"buckets": [
{
"key": "Samsung",
"doc_count": 5
},
]
}
}
But i still want to see in aggregations for all others brands with filtered size.
Something like:
"size": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 87,
"buckets": [
{
"key": "6",
"doc_count": 5
},
{
"key": "5,5",
"doc_count": 5
}
]
}
},
"brand": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 87,
"buckets": [
{
"key": "Apple",
"doc_count": 10
},
{
"key": "Samsung",
"doc_count": 5
},
]
}
}
Is this possible with ES?
Thank you so much for all answers.