es(Elasticsearch)查询报错: Set fielddata=true on [level] in order to load fielddata in memory by uninverting the inverted index
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.]];
修改es模板
PUT 索引名称/_mapping/_doc { "properties":{ "level":{ "type":"text", "fielddata": true } } }
level是代码中报错的字段,
或者下面这种简单解决办法
简单解决办法,代码查询的时候改为
searchSourceBuilder.sort("level.keyword", SortOrder.DESC);
加一个
.keyword