首页 > 其他分享 >ES 查询时提示:all shards failed [type=search_phase_execution_exception]

ES 查询时提示:all shards failed [type=search_phase_execution_exception]

时间:2022-11-14 11:04:09浏览次数:47  
标签:search keyword shards 查询 failed DSL exception execution

我的情况和解决方案

这种错误大概率是 ES 的查询语句语法错误,比如我当时是,时间筛选的条件的格式写错了,导致 ES 查询时解析错误,从而报了​​all shards failed [type=search_phase_execution_exception]​​这个错误

ES 查询时提示:all shards failed [type=search_phase_execution_exception]_解决方案

排查思路:先想办法把查询 DSL 语句打印出来,看下这个最终用来查询的 DSL 语句在语法上有没有问题,如果有问题就改正。

网上对于这个错误还有一些其他的原因,这里简单复制过来,方便以后遇到相同问题时查询使用

其他网友的情况和解决方案

当使用到term 查询的时候,由于是精准匹配,所以查询的关键字在 es 上的类型,必须是 keyword 而不能是 text,比如你的搜索条件是 “name”:”jack”,那么该 name 字段的 es 类型得是keyword,而不能是 text。比如下面是一个 DSL语句的例子,

ES 查询时提示:all shards failed [type=search_phase_execution_exception]_字段_02

解决方案一是修改 ES 的 mapping,把需要精准匹配的字段设置成 keyword 类型,

方案二是修改 DSL,让查询的字段类型按照 keyword 的方式来查询,query 里增加 ​​.keyword​​ 后缀。但是这种方案我都没有亲自实验过,不知道是否能真的解决问题,下次遇到了相同问题再来检验一下。

修改 DSL 中的语句,字段里增加​​.keyword​​ 后缀。

ES 查询时提示:all shards failed [type=search_phase_execution_exception]_字段_03

在我们的Java 或者 Golang 代码中怎么修改呢?如下,加上".keyword"就可以了

Java 客户端

ES 查询时提示:all shards failed [type=search_phase_execution_exception]_后缀_04

Golang 客户端

ES 查询时提示:all shards failed [type=search_phase_execution_exception]_字段_05

参考:​​已解决:Elasticsearch报错:exception [type=search_phase_execution_exception, reason=all shards failed]​​、​​all shards failed [type=search_phase_execution_exception]​​



标签:search,keyword,shards,查询,failed,DSL,exception,execution
From: https://blog.51cto.com/u_14201949/5848514

相关文章