在我們的一個新項目中,我們受此文章http://project-a.github.io/on-site-search-design-patterns-for-e-commerce/#generic-faceted-search的啓發,用於完成我們的「構面」結構。儘管我已經在文章描述的範圍內進行了工作,但我在選擇方面時遇到了讓它起作用的問題。我希望有人可以提供一些提示,以便嘗試,因此我不必再次將所有聚合重做爲單獨的聚合計算。Elasticsearch - 通用構面結構 - 計算聚合與濾波器組合
問題的根本在於我們使用單一聚合來一次計算所有「方面」,但是當我添加一個過濾器(fx。檢查品牌名稱)時,它會「刪除」所有其他品牌返回聚合。我基本想要的是,在計算其他方面時,它應該將該品牌用作過濾器,而不是在計算品牌聚合時使用該品牌。這是必要的,所以用戶可以例如選擇多個品牌。
查看https://www.contorion.de/search/Metabo_Fein/ou1-ou2?q=Winkelschleifer&c=bovy(這是上述文章中描述的網站),我選擇了「Metabo」和「Fein」製造商(Hersteller),並展開了Hersteller菜單,它顯示了所有制造商, 。所以我知道這是可能的,我希望那裏有人會提示如何編寫彙總/過濾器,這樣我就可以獲得「正確的電子商務行爲」。
在產品中ES我有以下結構:(相同的原始的文章中,儘管在命名「C#「指明分數」)
"attributeStrings": [
{
"facetName": "Property",
"facetValue": "Organic"
},
{
"facetName": "Property",
"facetValue": "Without parfume"
},
{
"facetName": "Brand",
"facetValue": "Adidas"
}
]
所以上面的產品具有2個屬性/面組 - 具有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"
}
]
} } } } } } } }
現在,如果我選擇屬性「有機」和品牌「阿迪達斯」我建了相同的聚集,但濾波器以應用這兩個約束(這是被它那種出錯...):
"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"
}
]
} } } } } } } }
我可以用這個模型中看到前進的唯一辦法,是計算彙總爲每個選定的面和莫名其妙合併的結果。但看起來非常複雜,有點像文章中描述的那樣模仿了這個模型,所以我希望有一個更清晰的解決方案,並且有人可以提供一些可以嘗試的提示。
非常感謝您對此的迴應和意見。 (對於遲到的反饋意見感到遺憾 - 流感得到了我的更好的體驗)。它確實很有意義,它在思考時似乎非常冗長,所以真的很高興能夠對此有所瞭解,也關於ES的性能。如果其他人也想這樣做,請仔細閱讀「哈卡」的答案,因爲它提供了一些提示,希望我一開始就讀得更細緻。 :) – Reonekot