ElasticSearch 错误 Fielddata is disabled on text fields by default. Set fielddata=true 解决办法

情况:
页面查询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配置时,还报错。

具体解决办法:
我直接重新创建模板,然后,重新刷一次数据,解决问题。

导入模板语句:

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"}}}}}'

查询导入是否成功:

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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值