解决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
        }
      }
    }
    

虽然篇幅比较短但是比较实用!!!

猜你喜欢

转载自blog.csdn.net/u011277745/article/details/127811056
今日推荐