我可以用此模型向前看的唯一方法是计算每个选定方面的聚合并以某种方式合并结果。
这是完全正确的。如果选择了一个构面(例如 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确实做好缓存单独的过滤条款,从而适用相同的筛选器在不同部分的查询应该便宜。
但是,这似乎非常复杂并且有点像文章中描述的那样具有模型的要点,因此我希望有一个更简洁的解决方案,并且有人可以提供一些尝试的提示。
实际上,您实际上无法将不同的过滤器应用于不同的方面,同时拥有不同的查询过滤器。如果您需要支持“正确的电子商务方面行为”,您将拥有复杂的查询:)
免责声明 :我是上述文章的合著者。



