我在电子商务网站的产品列表和产品搜索页面上使用elasticsearch。现在,您想在过滤中使用elasticsearch。在执行此操作时,我可以根据自己的过滤器获得适当的结果,但是无法为最终用户提供所获得的结果适当的过滤器元素。例如;我的产品列表页面上有5种不同尺寸和品牌的5种产品。根据这5个产品结果,我希望获得具有适当品牌和尺寸规格的过滤器列表。
elasticsearch结果列表文档示例:
"_source" : {
"name" : "Product 1",
"manufacturer" : {
"manufacturer_id" : 1,
"manufacturer_name" : "Brand 1"
},
"attribute" : [
{
"attribute_id" : 1,
"text" : "Other product attribute"
},
{ // I want this array
"attribute_id" : 2,
"text" : "Size product attribute (L)"
}
]
}
"_source" : {
"name" : "Product 2",
"manufacturer" : {
"manufacturer_id" : 2,
"manufacturer_name" : "Brand 2"
},
"attribute" : [
{
"attribute_id" : 1,
"text" : "Other product attribute"
},
{ // I want this array
"attribute_id" : 2,
"text" : "Size product attribute (XL)"
}
]
}
根据此映射,将有5个不同的产品和制造商系列。如何获得它们,如下所示?
"facets" : {
"manufacturers" : [
{
"manufacturer_id" : 1,
"manufacturer_name" : "Brand 1",
"count" : 1
},
{
"manufacturer_id" : 2,
"manufacturer_name" : "Brand 2",
"count" : 1
}
],
"attributes" : [
{ // I want this array
"attribute_id" : 2,
"text" : "Size product attribute (L)",
"count" : 1
},
{ // I want this array
"attribute_id" : 2,
"text" : "Size product attribute (XL)",
"count" : 1
}
]
}
预先感谢您的支持。