'How to fix ElasticSearch ‘Fielddata is disabled on text fields by default’ for keyword field

I'm getting the "Fielddata is disabled on text fields by default" on a keyword field. Below is the code.

{
 "aggs": {
   "agg_terms_user": {
     "terms": {
       "field": "user"
     }
   }
 }
}

The mapping for the user field is as below

user: { type: "keyword" }

Since the user field has type set as keyword I shouldn't get the error. However, the error is still thrown.

[illegal_argument_exception] Fielddata is disabled on text fields by default. Set fielddata=true on [user] 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.

I don't know what to try now.



Solution 1:[1]

The comment of @Andrey Borisko was correct

I used

"field": "user.keyword" 

instead of

"field": "user" 

based on Nikhil's example and it worked for me.

Solution 2:[2]

Check out the documentation in the elastic which clearly mentions that we cannot use the text field for aggregations, sorting, or scripting

https://www.elastic.co/guide/en/elasticsearch/reference/current/text.html#fielddata-mapping-param

This can be achieved with help of keyword usage. Try searching by

"field" : "user.keyword"

Solution 3:[3]

Facing the same issue in heartbeat application.I have solved this issue by following below steps.

  1. stop the application [ in my case I stopped the heartbeat application]

  2. Delete the index related to apps.

  3. Start the application

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Gino Mempin
Solution 2 Jayabharathi Palanisamy
Solution 3