es(Elasticsearch)查询报错: Set fielddata=true on [level] in order to load fielddata in memory by uninverting the inverted index

发布时间 2023-04-03 10:27:44作者: yvioo

 

Invocation of init method failed; nested exception is ElasticsearchStatusException[Elasticsearch exception [type=search_phase_execution_exception, reason=all shards failed]]; nested: ElasticsearchException[Elasticsearch exception [type=illegal_argument_exception, reason=Fielddata is disabled on text fields by default. Set fielddata=true on [level] 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.]]; nested: ElasticsearchException[Elasticsearch exception [type=illegal_argument_exception, reason=Fielddata is disabled on text fields by default. Set fielddata=true on [level] 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.]];

 

简单解决办法,代码查询的时候改为

 searchSourceBuilder.sort("level.keyword", SortOrder.DESC);

加一个

.keyword