在使用 java 编写 ES 的查询接口的时候,需要根据某关键字进行排序并返回数据,但是在排序的时候报错如下:
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 [subTaskId] 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 [subTaskId] 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.]]; at org.elasticsearch.rest.BytesRestResponse.errorFromXContent(BytesRestResponse.java:177) at org.elasticsearch.client.RestHighLevelClient.parseEntity(RestHighLevelClient.java:1793) at org.elasticsearch.client.RestHighLevelClient.parseResponseException(RestHighLevelClient.java:1769) at org.elasticsearch.client.RestHighLevelClient.internalPerformRequest(RestHighLevelClient.java:1606) at org.elasticsearch.client.RestHighLevelClient.performRequest(RestHighLevelClient.java:1563)解决方法
使用 谷歌的 Elastic Search Head 插件,然后执行以下命令:
{
"properties": {
"subTaskId": {
"type": "text",
"fielddata": true
}
}
}
然后点击左下角的 Request。
问题虽小,但是也挺烦心的。
Smileyan
2021.11.19 17:37



