You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Shopware 6.4对接Elasticsearch 7.17出现布尔值解析异常求助

Shopware 6.4 + Elasticsearch 7.17:布尔值[0]解析失败异常排查与解决

问题场景

当前运行环境为Shopware 6.4搭配Elasticsearch 7.17,未部署Kibana。多数搜索请求可正常执行,但偶尔触发Elasticsearch 400错误,错误提示为Can't parse boolean value [0], expected [true] or [false]。已知Elasticsearch 6+仅支持true/false作为布尔值输入,怀疑由第三方插件引发该问题,自行搜索未找到有效解决方案。

错误日志

[2023-09-15T08:48:23.462839+00:00] request.CRITICAL: Uncaught PHP Exception Elasticsearch\Common\Exceptions\BadRequest400Exception: "{\"error\":{\"root_cause\":[{\"type\":\"query_shard_exception\",\"reason\":\"failed to create query: Can't parse boolean value [0], expected [true] or [false]\",\"index_uuid\":\"Z-KvxYVyRzKeSEKaV23k6w\",\"index\":\"sw_product_2fbb5fe2e29a4d70aa5854ce7ce3e20b_1694688320\"}],\"type\":\"search_phase_execution_exception\",\"reason\":\"all shards failed\",\"phase\":\"query\",\"grouped\":true,\"failed_shards\":[{\"shard\":0,\"index\":\"sw_product_2fbb5fe2e29a4d70aa5854ce7ce3e20b_1694688320\",\"node\":\"yW9O2-UCSlCoYctoSmeXPQ\",\"reason\":{\"type\":\"query_shard_exception\",\"reason\":\"failed to create query: Can't parse boolean value [0], expected [true] or [false]\",\"index_uuid\":\"Z-KvxYVyRzKeSEKaV23k6w\",\"index\":\"sw_product_2fbb5fe2e29a4d70aa5854ce7ce3e20b_1694688320\",\"caused_by\":{\"type\":\"illegal_argument_exception\",\"reason\":\"Can't parse boolean value [0], expected [true] or [false]\"}}}]},\"status\":400}" at /vendor/elasticsearch/elasticsearch/src/Elasticsearch/Connections/Connection.php line 693 {\"exception\":\"[object] (Elasticsearch\\\\Common\\\\Exceptions\\\\BadRequest400Exception(code: 400): {\\\"error\\\":{\\\"root_cause\\\":[{\\\"type\\\":\\\"query_shard_exception\\\",\\\"reason\\\":\\\"failed to create query: Can't parse boolean value [0], expected [true] or [false]\\\",\\\"index_uuid\\\":\\\"Z-KvxYVyRzKeSEKaV23k6w\\\",\\\"index\\\":\\\"sw_product_2fbb5fe2e29a4d70aa5854ce7ce3e20b_1694688320\\\"}],\\\"type\\\":\\\"search_phase_execution_exception\\\",\\\"reason\\\":\\\"all shards failed\\\",\\\"phase\\\":\\\"query\\\",\\\"grouped\\\":true,\\\"failed_shards\\\":[{\\\"shard\\\":0,\\\"index\\\":\\\"sw_product_2fbb5fe2e29a4d70aa5854ce7ce3e20b_1694688320\\\",\\\"node\\\":\\\"yW9O2-UCSlCoYctoSmeXPQ\\\",\\\"reason\\\":{\\\"type\\\":\\\"query_shard_exception\\\",\\\"reason\\\":\\\"failed to create query: Can't parse boolean value [0], expected [true] or [false]\\\",\\\"index_uuid\\\":\\\"Z-KvxYVyRzKeSEKaV23k6w\\\",\\\"index\\\":\\\"sw_product_2fbb5fe2e29a4d70aa5854ce7ce3e20b_1694688320\\\",\\\"caused_by\\\":{\\\"type\\\":\\\"illegal_argument_exception\\\",\\\"reason\\\":\\\"Can't parse boolean value [0], expected [true] or [false]\\\"}}}]},\\\"status\\\":400} at /vendor/elasticsearch/elasticsearch/src/Elasticsearch/Connections/Connection.php:693)\"} []

排查与解决步骤

1. 定位异常请求的具体字段

  • 开启Shopware调试模式,捕获完整的Elasticsearch请求体:
    • 修改项目根目录的.env文件,设置APP_DEBUG=1和LOG_LEVEL=debug,重启应用后复现错误。
    • 在日志中查找触发错误的ES请求,定位到包含0/1值的布尔字段。

2. 排查第三方插件

  • 禁用所有第三方搜索、过滤类插件,逐个重新启用并测试,确认哪个插件启用后会触发异常。
  • 重点检查涉及产品状态(如是否上架、是否有库存)、自定义过滤条件的插件,它们的查询逻辑可能存在布尔值格式错误。

3. 临时兼容修复

如果暂时无法定位插件,可通过修改Elasticsearch索引映射实现兼容:

  • 针对出错的产品索引(如日志中的sw_product_2fbb5fe2e29a4d70aa5854ce7ce3e20b_1694688320),更新目标布尔字段的映射,开启coerce属性:
    PUT /sw_product_2fbb5fe2e29a4d70aa5854ce7ce3e20b_1694688320/_mapping
    {
      "properties": {
        "target_boolean_field": {
          "type": "boolean",
          "coerce": true
        }
      }
    }
    
  • 注意:此方案仅为临时兼容,后续重建索引或插件更新后可能复发,需彻底修复插件代码。

4. 代码层面彻底修复

找到触发问题的插件代码,将所有布尔值参数从0/1替换为false/true:

// 错误示例
$query['bool']['filter'][] = ['term' => ['is_active' => 0]];
// 修复后
$query['bool']['filter'][] = ['term' => ['is_active' => false]];

内容的提问来源于stack exchange,提问作者Karol Adamus

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.11 01:53:14