I have next mapping for field in Elastic Search (definition in YML):
my_analyzer:
type: custom
tokenizer: keyword
filter: lowercase
products_filter:
type: "nested"
properties:
filter_name: {"type" : "string", analyzer: "my_analyzer"}
filter_value: {"type" : "string" , analyzer: "my_analyzer"}
Each document has a lot of filters and it looks like:
"products_filter": [
{
"filter_name": "Rahmengröße",
"filter_value": "33,5 cm"
}
,
{
"filter_name": "color",
"filter_value": "gelb"
}
,
{
"filter_name": "Rahmengröße",
"filter_value": "39,5 cm"
}
,
{
"filter_name": "Rahmengröße",
"filter_value": "45,5 cm"
}]
I trying to get a list of unique filter names and list of unique filter values for each filter.
I mean, I want to get structure like:
Rahmengröße:
39,5 cm
45,5 cm
33,5 cm
Color:
gelb
To get it I tried few variants of aggregation, for example:
{
"aggs": {
"bla": {
"terms": {
"field": "products_filter.filter_name"
},
"aggs": {
"bla2": {
"terms": {
"field": "products_filter.filter_value"
}
}
}
}
}
}
And this request is wrong.
It will return me list of unique filter names, and each will contain list of ALL filter_values.
"bla": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 103,
"buckets": [
{
"key": "color",
"doc_count": 9,
"bla2": {
"doc_count_error_upper_bound": 4,
"sum_other_doc_count": 366,
"buckets": [
{
"key": "100",
"doc_count": 5
}
,
{
"key": "cm",
"doc_count": 5
}
,
{
"key": "unisex",
"doc_count": 5
}
,
{
"key": "11",
"doc_count": 4
}
,
{
"key": "160",
"doc_count": 4
}
,
{
"key": "22",
"doc_count": 4
}
,
{
"key": "a",
"doc_count": 4
}
,
{
"key": "alu",
"doc_count": 4
}
,
{
"key": "aluminium",
"doc_count": 4
}
,
{
"key": "aus",
"doc_count": 4
}
]
}
}
,
Additionally I tried to use Reverse nested aggregation, but it doesnt help me.
So I think there some logical fault in my attempts?