我们在一个新项目中受到了这篇文章的启发,链接为http://project-a.github.io/on-site-search-design-patterns-for-e-commerce/#generic-faceted-search。我们采用了“facet”结构。虽然我已经按照文章的描述使其发挥作用,但在选择特征时遇到了问题。希望有人能够给一个提示,让我不必重新将所有聚合计算分开。
问题基本上是我们使用单个聚合在同时计算所有“特征”时,但在添加筛选(例如检查品牌名称)时,返回聚合时会“移除”所有其他品牌。我想要的基本上是,在计算其他特征时应该将该品牌用作过滤器,但在计算品牌聚合时不应该加以考虑。这是必要的,以便用户可以选择多个品牌。
查看https://www.contorion.de/search/Metabo_Fein/ou1-ou2?q=Winkelschleifer&c=bovy(即上述文章中描述的网站),我已经选择了“Metabo”和“Fein”制造商(Hersteller),展开 Hersteller 菜单,它显示了所有制造商而不仅仅是所选的制造商。所以我知道这是可能的,希望有人能够提示如何编写聚合/筛选,以便实现“正确的电子商务特征行为”。
在 ES 中的产品具有以下结构:(与原始文章相同,但使用了“C#'ified”中的命名)
"attributeStrings": [
{
"facetName": "Property",
"facetValue": "Organic"
},
{
"facetName": "Property",
"facetValue": "Without parfume"
},
{
"facetName": "Brand",
"facetValue": "Adidas"
}
]
所以上述产品有两个属性/方面组 - 具有2个值的属性(有机,无香味)和具有1个值的品牌(阿迪达斯)。 没有任何过滤器,我从以下查询计算聚合:
"aggs": {
"agg_attr_strings_filter": {
"filter": {},
"aggs": {
"agg_attr_strings": {
"nested": {
"path": "attributeStrings"
},
"aggs": {
"attr_name": {
"terms": {
"field": "attributeStrings.facetName"
},
"aggs": {
"attr_value": {
"terms": {
"field": "attributeStrings.facetValue",
"size": 1000,
"order": [
{
"_term": "asc"
}
]
} } } } } } } }
现在,如果我选择属性为“有机”的品牌为“Adidas”,那么我将构建相同的聚合,但需要应用这两个约束条件的过滤器(这就是出问题的地方...):
"aggs": {
"agg_attr_strings_filter": {
"filter": {
"bool": {
"filter": [
{
"nested": {
"query": {
"bool": {
"filter": [
{
"term": {
"attributeStrings.facetName": {
"value": "Property"
}
}
},
{
"terms": {
"attributeStrings.facetValue": [
"Organic"
]
}
}
]
}
},
"path": "attributeStrings"
}
},
{
"nested": {
"query": {
"bool": {
"filter": [
{
"term": {
"attributeStrings.facetName": {
"value": "Brand"
}
}
},
{
"terms": {
"attributeStrings.facetValue": [
"Adidas"
]
}
}
]
}
},
"path": "attributeStrings"
}
}
]
}
},
"aggs": {
"agg_attr_strings": {
"nested": {
"path": "attributeStrings"
},
"aggs": {
"attr_name": {
"terms": {
"field": "attributeStrings.facetName",
},
"aggs": {
"attr_value": {
"terms": {
"field": "attributeStrings.facetValue",
"size": 1000,
"order": [
{
"_term": "asc"
}
]
} } } } } } } }
我能看到这个模型向前发展的唯一方式是计算每个选择的方面的聚合,并且以某种方式合并结果。但这似乎非常复杂,而且有点违背了文章中描述的模型的初衷,所以我希望有更简洁的解决方案,并且希望有人能够给出一些尝试的提示。