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

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

我的情况和解决方案

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

1456655-20221105173856316-1767892694.png

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

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

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

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

1456655-20221105175544256-829310807.png

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

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

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

Java 客户端1456655-20221105175741064-1513801291.png

Golang 客户端

1456655-20221105175922754-276638120.png

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


目录
打赏
0
0
0
0
13
分享
相关文章
ES集群报错 failed to send join request to maste
ES集群报错 failed to send join request to maste
278 0
|
10月前
Error:Execution failed for task ':app:processDebugManifest'. > Manifest merger failed with multiple
Error:Execution failed for task ':app:processDebugManifest'. > Manifest merger failed with multiple
75 1
|
10月前
|
hibernate5 Cannot create TypedQuery for query with more than one return using requested result type
hibernate5 Cannot create TypedQuery for query with more than one return using requested result type
95 0
Error getting generated key or setting result to parameter object.必须执行该语句才能获得结果。
Error getting generated key or setting result to parameter object.必须执行该语句才能获得结果。
2855 47
|
9月前
|
Elasticsearch exception [type=cluster_block_exception, reason=blocked by: [FORBIDDEN/12/index r【已解决】
Elasticsearch exception [type=cluster_block_exception, reason=blocked by: [FORBIDDEN/12/index r【已解决】
189 1
Error:Execution failed for task ‘:app:preDebugAndroidTestBuild’. Conflict with dependency ‘com.andr
Error:Execution failed for task ‘:app:preDebugAndroidTestBuild’. Conflict with dependency ‘com.andr
45 1
|
10月前
|
Elasticsearch exception [type=illegal_argument_exception, reason=index [.1] is the write index for data stream [slowlog] and cannot be deleted]
在 Elasticsearch 中,你尝试删除的索引是一个数据流(data stream)的一部分,而且是数据流的写入索引(write index),因此无法直接删除它。为了解决这个问题,你可以按照以下步骤进行操作:
847 0
|
10月前
Error:Execution failed for task ':app:javaPreCompileDebug'. > Annotation processors must be explicit
Error:Execution failed for task ':app:javaPreCompileDebug'. > Annotation processors must be explicit
123 0
|
10月前
|
Error:Execution failed for task ':transformClassesAndResourcesWithProguardForRelease'
Error:Execution failed for task ':transformClassesAndResourcesWithProguardForRelease'
85 0
|
10月前
|
Build desc failed:Fetch table group shards failed on meta proxy:Loading cached shard 1ocation value for table group[dwhg_scm.dwhg_prd_tg_default] failed
Build desc failed:Fetch table group shards failed on meta proxy:Loading cached shard 1ocation value for table group[dwhg_scm.dwhg_prd_tg_default] failed
233 2

热门文章

最新文章