ElasticSearch 5.1 Fielddata is disabled by default in the text field [ERROR: attempt to use aggregation in the field]

The presence of this field in my display

"answer": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } }, 

I am trying to perform this aggregation

 "aggs": { "answer": { "terms": { "field": "answer" } }, 

but i get this error

 "type": "illegal_argument_exception", "reason": "Fielddata is disabled on text fields by default. Set fielddata=true on [answer] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory." 

Do I need to change my mapping or am I using the wrong aggregation? (just upgraded from 2.x to 5.1)

+5
source share
3 answers

You need to aggregate in the keyword subfield, for example:

 "aggs": { "answer": { "terms": { "field": "answer.keyword" } }, 

This will work.

+13
source

By adding @Val to the answer, you can also set fielddata to true during the display itself:

 "answer": { "type": "text", "fielddata": true, <-- add this line "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } }, 
+1
source

In aggregation, just add a response keyword. He worked for me. For text fields we need to add a keyword. "field": "answer.keyword"

+1
source

Source: https://habr.com/ru/post/1262352/


All Articles