I have products with dynamic attributes (filters). I need to get dynamically counts for each value for the filter according to the search query.
I have following mapping for products index:
{
"products":{
"mappings":{
"properties":{
...
"dynamicFilters":{
"type":"nested",
"properties":{
"name":{
"type":"keyword"
},
"value":{
"type":"keyword"
}
}
},
...
}
}
}
}
And following aggregation request:
'size': 0,
'query': {
'bool': {
'must': {
'match': {
'category': 'Notebooks'
}
},
'filter': {
{'nested': {
'path': 'dynamicFilters',
'query': {
'bool': {
'filter': {
{'term': {'dynamicFilters.name': 'processor'}},
{'terms': {'dynamicFilters.value': {'Ryzen 7'}}},
},
}
}
},
}
}
},
'aggs': {
//'dynamicFilters': {
//'global': {}, <-- global type commented here
//'aggs': {
'dynamicFilters': {
'nested': {
'path': 'dynamicFilters',
},
'aggs': {
'name': {
'terms': {
'field': dynamicFilters.name',
'size': 20
},
'aggs': {
'value': {
'terms': {
'field': 'dynamicFilters.value',
'size': 20
}
}
}
},
}
},
//}
//}
},
The problem is when in the search query will be enabled filter, for instance, "proccesor" with value "Ryzen 7" - in response won't be aggregation for all "processor" values, except "Ryzen 7".
I've tried to make this work with global type
, but in this case aggs stops working with search query and return all existing counts for values.
Any help will be highly appreciated, thank you!