栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

Elasticsearch-通用构面结构-计算与过滤器组合的聚合

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Elasticsearch-通用构面结构-计算与过滤器组合的聚合

我可以用此模型向前看的唯一方法是计算每个选定方面的聚合并以某种方式合并结果。

这是完全正确的。如果选择了一个构面(例如 brand ),则如果您还想获取其他品牌进行多选,则无法使用全局品牌过滤器。您可以做的是将所有 其他
过滤器应用于选定的方面,并将 所有 过滤器
应用于未选定的方面。结果,您将为选定的过滤器

n+1
单独聚集
n
-第一个聚集针对所有构面,其余聚集于选定构面。

在您的情况下,查询可能类似于:

{  "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"}         ]       }     }   } }          }        }      }    },    "special_agg_property": {      "filter": {        "nested": {          "query": { "bool": {   "filter": [     {       "term": {         "attributeStrings.facetName": {"value": "Brand"         }       }     },     {       "terms": {         "attributeStrings.facetValue": ["Adidas"         ]       }     }   ] }          },          "path": "attributeStrings"        }      },      "aggs": {        "special_agg_property": {          "nested": { "path": "attributeStrings"          },          "aggs": { "agg_filtered_special": {   "filter": {     "query": {       "match": {         "attributeStrings.facetName": "Property"       }     }   },   "aggs": {     "facet_value": {       "terms": {         "size": 1000,         "field": "attributeStrings.facetValue"       }     }   } }          }        }      }    },    "special_agg_brand": {      "filter": {        "nested": {          "query": { "bool": {   "filter": [     {       "term": {         "attributeStrings.facetName": {"value": "Property"         }       }     },     {       "terms": {         "attributeStrings.facetValue": ["Organic"         ]       }     }   ] }          },          "path": "attributeStrings"        }      },      "aggs": {        "special_agg_brand": {          "nested": { "path": "attributeStrings"          },          "aggs": { "agg_filtered_special": {   "filter": {     "query": {       "match": {         "attributeStrings.facetName": "Brand"       }     }   },   "aggs": {     "facet_value": {       "terms": {         "size": 1000,         "field": "attributeStrings.facetValue"       }     }   } }          }        }      }    }  }}

这个查询看起来超级大而且令人恐惧,但是生成这样的查询可以用几十行代码来完成。解析查询结果时,您需要首先解析常规聚合(使用所有过滤器的聚合),然后进行特殊构面聚合。从上面的示例,从第一解析结果

agg_attr_strings_filter
,但这些结果也将包含聚集值的
品牌财产 应该由聚集值覆盖
special_agg_property
,并
special_agg_brand

另外,这个查询是有效的,因为Elasticsearch确实做好缓存单独的过滤条款,从而适用相同的筛选器在不同部分的查询应该便宜。

但是,这似乎非常复杂并且有点像文章中描述的那样具有模型的要点,因此我希望有一个更简洁的解决方案,并且有人可以提供一些尝试的提示。

实际上,您实际上无法将不同的过滤器应用于不同的方面,同时拥有不同的查询过滤器。如果您需要支持“正确的电子商务方面行为”,您将拥有复杂的查询:)

免责声明 :我是上述文章的合著者。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/401391.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号