I am trying to accomplish case-insensitive aggregation filters on fields with multiple values as via scripting as shown here: Support case_insensitive for 'Include' of Terms Aggregation · Issue #68819 · elastic/elasticsearch · GitHub.
The way I have set up my mappings is such that each text field has multi-fields for sorting and aggregating. For instance:
"Contacts": {
"type": "text",
"fields": {
"agg": {
"type": "keyword",
"ignore_above": 256,
"normalizer": "trimNormalizer"
},
"sort": {
"type": "keyword",
"ignore_above": 256,
"normalizer": "sortNormalizer"
}
},
"analyzer": "searchAnalyzer"
}
If I try to use a script to create a case-insensitive aggregation filter on the field Contacts.agg I receive an error, which I believe is a bug. This is my query:
{
"track_total_hits": true,
"size": 0,
"runtime_mappings": {
"insensitive_matches": {
"type": "keyword",
"script": {
"source": "for (String contact : doc.Contacts.agg) { if (contact.toLowerCase(Locale.ROOT).contains('amelia')) { emit(contact); } }"
}
}
},
"aggs": {
"fieldAgg": {
"terms": {
"field": "insensitive_matches",
"size": 200
}
}
}
}
And this is the error I receive:
"for (String contact : doc.Contacts.agg) { ",
" ^---- HERE"
"Fielddata is disabled on [Contacts] in [orgs]. Text fields are not optimised for operations that require per-document field data like aggregations and sorting, so these operations are disabled by default. Please use a keyword field instead. Alternatively, set fielddata=true on [Contacts] in order to load field data by uninverting the inverted index. Note that this can use significant memory."
This is with version 8.11.0.