Within a Python project I have an elastic search index that throws the following error when I sort on a given field: elasticsearch.exceptions.RequestError: RequestError(400, 'search_phase_execution_exception', 'Fielddata is disabled on text fields by default. Set fielddata=true on [my_field] 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.')
Originally this was a text field and so I did what the message recommended and tried changing it to a keyword field or setting fielddata=True. Unfortunately, those changes still result in the exact same error message and so now I am confused.
Here are the different ways I have tried defining the field in my document index. All result in the same error.
from elasticsearch_dsl import DocType, Index, field, Keyword
class MyDoc(DocType):
my_field = field.Text(fields={'raw': field.Keyword()})
my_field = field.Keyword(fielddata=True)
my_field = field.Keyword()
my_field = Keyword()
my_field = Keyword(fields={'raw': field.Keyword()})
My index mapping:
{
my-index: {
mappings: {
doc: {
properties: {
code: {
type: "text",
fields: {
keyword: {
type: "keyword",
ignore_above: 256
}
}
},
my_field: {
type: "text",
fields: {
keyword: {
type: "keyword",
ignore_above: 256
}
}
}
}
}
}
}
}
My Query:
{'query': {'bool': {'filter': [{'bool': {'must_not': [{'terms': {'code': []}}]}}]}}, 'sort': ['my_field'], 'from': 0, 'size': 6}