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]


相关文章
|
1天前
Error:Execution failed for task ':app:processDebugManifest'. > Manifest merger failed with multiple
Error:Execution failed for task ':app:processDebugManifest'. > Manifest merger failed with multiple
14 1
|
XML SQL 数据库
Error getting generated key or setting result to parameter object.必须执行该语句才能获得结果。
Error getting generated key or setting result to parameter object.必须执行该语句才能获得结果。
|
1天前
|
索引
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),因此无法直接删除它。为了解决这个问题,你可以按照以下步骤进行操作:
|
1天前
|
缓存 Java 开发工具
Error:Execution failed for task ‘:app:preDebugAndroidTestBuild’. Conflict with dependency ‘com.andr
Error:Execution failed for task ‘:app:preDebugAndroidTestBuild’. Conflict with dependency ‘com.andr
11 1
|
1天前
Error:Execution failed for task ':app:javaPreCompileDebug'. > Annotation processors must be explicit
Error:Execution failed for task ':app:javaPreCompileDebug'. > Annotation processors must be explicit
68 0
|
1天前
|
存储
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
45 2
|
12月前
|
开发者 iOS开发
Xcode运行报错The operation couldn’t be completed. Unable to launch xxx because it has an invalid code...
Xcode运行报错The operation couldn’t be completed. Unable to launch xxx because it has an invalid code...
671 0
Elasticsearch exception [type=search_phase_execution_exception, reason=all shards failed]
Elasticsearch exception [type=search_phase_execution_exception, reason=all shards failed]
Elasticsearch exception [type=search_phase_execution_exception, reason=all shards failed]
|
索引
ES报错:“type“=>“cluster_block_exception“, “reason“=>“blocked by: [FORBIDDEN/12/index read-only / allow
ES报错:“type“=>“cluster_block_exception“, “reason“=>“blocked by: [FORBIDDEN/12/index read-only / allow
276 0
ES报错:“type“=>“cluster_block_exception“, “reason“=>“blocked by: [FORBIDDEN/12/index read-only / allow