Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 523
Nikhil Avatar asked Dec 12 '19 05:12

Nikhil


2 Answers

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.

like image 159
Investigator Avatar answered Oct 23 '22 12:10

Investigator


I found the reason behind the unexpected error. The ES wasn't getting re-indexed properly. Once I deleted the indexed first and then recreated it then it started working like a charm.

like image 45
Nikhil Avatar answered Oct 23 '22 11:10

Nikhil