Shopware 6高级搜索按嵌套布尔字段排序时判定其为空
Shopware嵌套布尔字段排序异常问题
问题概述
在Shopware前台使用SwagEnterpriseSearchPlatform提升搜索速度,为product表自定义了productInfo嵌套扩展,包含以下字段:
isRejected:布尔类型flags:关键字类型isAvailable:布尔类型
尝试按嵌套字段productInfo.isAvailable排序搜索结果时,结果未正确排序,响应中所有条目的sort值均为9223372036854775807;但按productInfo.flags排序时结果正常。经确认,搜索索引中存在这些嵌套布尔字段,且所有嵌套布尔字段均出现此排序异常问题。
请求与响应示例
按productInfo.isAvailable排序
请求体
{ "query":{ "bool":{ "filter":[ { "terms":{ "id":[ "58d2bd4e1a1f47168aa3bf85cf6c5a68", "e41101c882f740fbbafa5667e5929a6b", "866e2a1e7a2643c084f07424300ab5ed" ] } }, { "bool":{ "must":[ { "nested":{ "path":"visibilities", "query":{ "bool":{ "must":[ { "range":{ "visibilities.visibility":{ "gte":10 } } }, { "term":{ "visibilities.salesChannelId":"3b7b6ced513e4f6e9e59133ed2cfa160" } } ] } } } }, { "term":{ "active":true } } ] } } ] } }, "from":0, "size":10000, "sort":[ { "productInfo.isAvailable":{ "order":"asc", "nested":{ "path":"productInfo" } } } ] }
响应体
{ "took":7, "timed_out":false, "_shards":{ "total":3, "successful":3, "skipped":0, "failed":0 }, "hits":{ "total":{ "value":3, "relation":"eq" }, "max_score":null, "hits":[ { "_index":"sw_product_5a2922f24a674e98801c1add4594e6a1_1692811773", "_type":"_doc", "_id":"58d2bd4e1a1f47168aa3bf85cf6c5a68", "_score":null, "_ignored":[ "createdAt" ], "_source":{ "fullText":"ASPIRIN PLUS C 01894063", "id":"58d2bd4e1a1f47168aa3bf85cf6c5a68", "fullTextBoosted":"ASPIRIN PLUS C 01894063" }, "sort":[ 9223372036854775807 ] }, { "_index":"sw_product_5a2922f24a674e98801c1add4594e6a1_1692811773", "_type":"_doc", "_id":"e41101c882f740fbbafa5667e5929a6b", "_score":null, "_ignored":[ "createdAt" ], "_source":{ "fullText":"ASPIRIN 500MG UEBERZ TABL 10203632", "id":"e41101c882f740fbbafa5667e5929a6b", "fullTextBoosted":"ASPIRIN 500MG UEBERZ TABL 10203632" }, "sort":[ 9223372036854775807 ] }, { "_index":"sw_product_5a2922f24a674e98801c1add4594e6a1_1692811773", "_type":"_doc", "_id":"866e2a1e7a2643c084f07424300ab5ed", "_score":null, "_ignored":[ "createdAt" ], "_source":{ "fullText":"ASPIRIN MIGRAENE 00958281", "id":"866e2a1e7a2643c084f07424300ab5ed", "fullTextBoosted":"ASPIRIN MIGRAENE 00958281" }, "sort":[ 9223372036854775807 ] } ] } }
按productInfo.flags排序
请求体
{ "query":{ "bool":{ "filter":[ { "terms":{ "id":[ "866e2a1e7a2643c084f07424300ab5ed", "58d2bd4e1a1f47168aa3bf85cf6c5a68", "e41101c882f740fbbafa5667e5929a6b" ] } }, { "bool":{ "must":[ { "nested":{ "path":"visibilities", "query":{ "bool":{ "must":[ { "range":{ "visibilities.visibility":{ "gte":10 } } }, { "term":{ "visibilities.salesChannelId":"3b7b6ced513e4f6e9e59133ed2cfa160" } } ] } } } }, { "term":{ "active":true } } ] } } ] } }, "from":0, "size":10000, "sort":[ { "productInfo.flags":{ "order":"desc", "nested":{ "path":"productInfo" } } } ] }
响应体
{ "took":9, "timed_out":false, "_shards":{ "total":3, "successful":3, "skipped":0, "failed":0 }, "hits":{ "total":{ "value":3, "relation":"eq" }, "max_score":null, "hits":[ { "_index":"sw_product_5a2922f24a674e98801c1add4594e6a1_1692811773", "_type":"_doc", "_id":"866e2a1e7a2643c084f07424300ab5ed", "_score":null, "_ignored":[ "createdAt" ], "_source":{ "fullText":"ASPIRIN MIGRAENE 00958281", "id":"866e2a1e7a2643c084f07424300ab5ed", "fullTextBoosted":"ASPIRIN MIGRAENE 00958281" }, "sort":[ "[\"1\", \"11\"]" ] }, { "_index":"sw_product_5a2922f24a674e98801c1add4594e6a1_1692811773", "_type":"_doc", "_id":"58d2bd4e1a1f47168aa3bf85cf6c5a68", "_score":null, "_ignored":[ "createdAt" ], "_source":{ "fullText":"ASPIRIN PLUS C 01894063", "id":"58d2bd4e1a1f47168aa3bf85cf6c5a68", "fullTextBoosted":"ASPIRIN PLUS C 01894063" }, "sort":[ "[\"1\", \"11\", \"9\", \"10\", \"13\"]" ] }, { "_index":"sw_product_5a2922f24a674e98801c1add4594e6a1_1692811773", "_type":"_doc", "_id":"e41101c882f740fbbafa5667e5929a6b", "_score":null, "_ignored":[ "createdAt" ], "_source":{ "fullText":"ASPIRIN 500MG UEBERZ TABL 10203632", "id":"e41101c882f740fbbafa5667e5929a6b", "fullTextBoosted":"ASPIRIN 500MG UEBERZ TABL 10203632" }, "sort":[ "[\"1\", \"10\", \"11\"]" ] } ] } }
索引结构
"productInfo":{ "type":"nested", "properties":{ "flags":{ "type":"keyword", "normalizer":"sw_lowercase_normalizer" }, "isAvailable":{ "type":"boolean" }, "isRejected":{ "type":"boolean" } } }
使用软件版本
- Shopware 6.4.20.2
- SwagEnterpriseSearchPlatform 3.4.2
- Elasticsearch 7.17.10
- MySQL 8.0.34
内容的提问来源于stack exchange,提问作者Gabriel
相关产品推荐
相关产品推荐

