We consume and store data containing a field filter_properties containing key => value fields.
Up until now we use dynamic mapping to store that data but that's creating a lot of unique fields.
So I decided to try the flattened_field type.
I now have a mapping looking like this:
{
"mappings" : {
"dynamic_templates" : [
{
"filterprops" : {
"path_match" : "filter_properties.*",
"mapping" : {
"fields" : {
"analyzed" : {
"normalizer" : "sort_normalizer",
"type" : "keyword"
}
},
"index" : true,
"norms" : false,
"type" : "keyword"
}
}
}
],
"properties": {
"filters" : {
"dynamic" : "strict",
"properties" : {
"analyzed" : {
"type" : "flattened",
"eager_global_ordinals": true
},
"raw" : {
"type" : "flattened",
"eager_global_ordinals": true
}
}
}
}
}
}
But doing aggregations using the new filters fields is "very" slow.
Doing a query like this (using the flattened_field) takes between 200/300 ms
POST my_index/_search
{
"query": {
"match_all": {}
},
"aggs": {
"foo": {
"terms": {
"field": "filters.raw.QBC",
"size": 300
}
}
}
}
Where this query on the same index takes between 20/30 ms
POST my_index/_search
{
"query": {
"match_all": {}
},
"aggs": {
"foo": {
"terms": {
"field": "filters_propertied.QBC",
"size": 300
}
}
}
}
Clearly I'm missing something here but I don't see it. Anyone have any pointers for me?