情况:
页面查询ES数据,Java查询报这个错误,但是,通过打印的语句,构建curl
查询时候又是正常的,这就让我很费解。
报错信息:
{
"error": {
"root_cause": [
{
"type": "illegal_argument_exception",
"reason": "Fielddata is disabled on text fields by default. Set fielddata=true on [aaa] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory."
}
],
"type": "search_phase_execution_exception",
"reason": "all shards failed",
"phase": "query",
"grouped": true,
"failed_shards": [
{
"shard": 0,
"index": "aaa_bbb_info_2022-09-27",
"node": "CqKuZyFxSYqCsgaXM7jX2A",
"reason": {
"type": "illegal_argument_exception",
"reason": "Fielddata is disabled on text fields by default. Set fielddata=true on [aaa] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory."
}
}
],
"caused_by": {
"type": "illegal_argument_exception",
"reason": "Fielddata is disabled on text fields by default. Set fielddata=true on [aaa] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory."
}
},
"status": 400
}
网上的解决办法:
https://blog.csdn.net/qq_16417621/article/details/105859887
这个解决办法其实是正确的,但是,有个前提条件,我们已经导入过模板,所以,可以直接修改模板
而且,这个帖子中的语句,是基于 ES7 的。我所在环境是ES5的,所以,加fielddata=true配置时,还报错。
具体解决办法:
我直接重新创建模板,然后,重新刷一次数据,解决问题。
导入模板语句:文章来源:https://www.toymoban.com/news/detail-599220.html
curl -X PUT -u elastic:123456 "http://127.0.0.1:9200/_template/aaa_bbb_info_temple" -H 'Content-Type: application/json' -d'{"template":"aaa_bbb_*","settings":{"index":{"mapping":{"ignore_malformed":"true"},"refresh_interval":"20s","number_of_shards":"5","translog":{"flush_threshold_size":"512mb","sync_interval":"60s","durability":"async"},"number_of_replicas":"1"}},"mappings":{"default":{"properties":{"aaa":{"store":true,"type":"keyword"}}}}}'
查询导入是否成功:文章来源地址https://www.toymoban.com/news/detail-599220.html
curl -H "Content-Type:application/json" -XGET -u elastic:123456 '192.168.92.82:9222/_template/aaa_bbb_info_temple' > aaa_bbb_info_temple.txt
到了这里,关于ElasticSearch 错误 Fielddata is disabled on text fields by default. Set fielddata=true 解决办法的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!