解决Elasticsearch报错:exception [type=search_phase_execution_exception, reason=all shards failed]

关于exception [type=search_phase_execution_exception, reason=all shards failed]这个es错误我是如何解决的!

由于服务器性能不佳,导致我的es挂了一次,将es修复后发现搜索功能出现了问题,错误日志内容如下:
服务器发生异常:ElasticsearchStatusException[Elasticsearch exception [type=search_phase_execution_exception, reason=all shards failed]]; 
发现这个错误好长时间了,因为最近比较忙,一直没有顾上去解决它,今天我分享一下我是如何解决这个问题的.
  1. 首先将异常级别升级到最高:Throwable

    try {
          response = client.search(searchRequest, RequestOptions.DEFAULT);
        } catch (Throwable e) {
          throw new RuntimeException(e);
        }
    
  2. 此时错误日志打印的比较详细,内容会变成这个样子:

    服务器发生异常: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 [created] 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 [created] 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.]];
    
  3. 此时我们可以进准的定位到是mapping的哪个字段有问题,我的这里是created,错误原因是我将created设置成了text,但是它的fielddata没有设置成true

  4. 接下来只要将这个字段的fielddata设置为true即可

    {
      "properties": {
        "created": { 
          "type":"text",
          "fielddata": true
        }
      }
    }
    
虽然篇幅比较短但是比较实用!!!
  • 7
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

乐观的Terry

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值