Behebung von ElasticSearch 'Fielddata is disabled on text fields by default' für Keyword-Feld
English
Deutsch
Problem:
Du hast ein Feld in ElasticSearch namens z.B. patterns vom Typ keyword. Wenn du jedoch eine Aggregation für dieses Feld abfragst, z.B.
es_fielddata_example.py
es.search(index="strings", body={
"size": 0,
"aggs" : {
"patterns" : {
"terms" : { "field" : "pattern" }
}
}
})siehst du diese Fehlermeldung:
es_fielddata_error.txt
elasticsearch.exceptions.RequestError: RequestError(400, 'search_phase_execution_exception', 'Fielddata is disabled on text fields by default. Set fielddata=true on [pattern] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory. Alternatively use a keyword field instead.'Lösung
Diese Fehlermeldung ist verwirrend, da du bereits ein keyword-Feld hast. Die ElasticSearch-Fielddata-Dokumentation sagt uns jedoch, dass du pattern.keyword in der Abfrage anstelle von nur pattern verwenden musst.
Vollständiges Beispiel:
es_fielddata_fix.py
es.search(index="strings", body={
"size": 0,
"aggs" : {
"patterns" : {
"terms" : { "field" : "pattern.keyword" }
}
}
})Check out similar posts by category:
Databases, ElasticSearch
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow