Error: Fielddata is disabled on text fields

I am following the operation of the video "getting started with Elasticsearch", https://www.elastic.co/webinars/getting-started-elasticsearch.

I post several indices into the Elasticsearch by using POST /inspections/_doc/_bulk, the documents of the indices include "inspection_score": 96 . But when I use the following command to sort the documents according to the value of "inspection_score", just as the video does.
GET /inspections/_doc/_search
{
"query":{
"range": {
"inspection_score": {
"gte": 80
}
}
},
"sort":[
{
"inspection_score": "desc"

}
]

}

I got the error: "Fielddata is disabled on text fields by default. Set fielddata=true on [inspection_score] in order to load fielddata in memory by uninverting the inverted index.

Why? The video shows everything is fine. By the way, is "inspection_score" of type text? I think it maybe number since in the POST command, I specify a number to the value of "inspection_score".

hi @li_jessen2016

fielddata is indeed disabled by default on text-fields. For more info see here https://www.elastic.co/guide/en/elasticsearch/reference/current/fielddata.html#_fielddata_is_disabled_on_literal_text_literal_fields_by_default

I would first check the mapping of your index, and verify what field-type the inspection_score field has.

I delete the indices. And post in bulk again. It works. It maybe previously I used "96" text as the value of inspection_score and it stayed there until I deleted them all.

PUT /index_name
{
your mapping here
"mappings": {}
}

First use this method to create a mapping for your index. Then push the data.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.