我用3个过滤器过滤了查询:"query": "iphone", color:5, category:10, brand:25.
我怎样才能获得其中有各个品牌的产品数量color:5和category:10?
在Solr我做到了:
fq={!tag=tag_facet_brand}facet_brand:"564"&facet.field={!ex=tag_facet_brand}facet_brand
Run Code Online (Sandbox Code Playgroud)
如何从聚合上下文中排除1个过滤器?(我不能使用全局,因为我松了query:iphone,我不能使用post_filter - 因为性能).
我是ES的新手,并且一直在尝试以与大多数大型电子商务商店相同的方式实现分面导航.
我的部分产品映射如下所示:
'name' => [
'type' => 'string',
'analyzer' => 'english_analyzer',
],
'range' => [
'type' => 'string',
'analyzer' => 'english_analyzer',
],
'filters' => [
'type' => 'nested',
'properties' => [
'name' => [
'type' => 'string',
'index' => 'not_analyzed',
],
'values' => [
'type' => 'object',
'properties' => [
'name' => [
'type' => 'string',
'index' => 'not_analyzed',
]
]
]
]
],
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,我将facets作为嵌套对象存储在"filters"中.
在我的搜索查询中,我可以将此聚合添加到我的查询中:
'aggs' => [
'facets' => [
'nested' => ['path' => 'filters'],
'aggs' => [ …Run Code Online (Sandbox Code Playgroud) 我想为facet查询UI计算facet计数,但我想我错过了一些东西,因为我无法使用facet过滤器得到我需要的数字.
这是一个例子.给出两个方面,每个方面有三个可能的术语:
Colors: {red, yellow, blue}
Notes: {do, re, mi}
Run Code Online (Sandbox Code Playgroud)
当我进行搜索时,构面中每个术语的计数不会考虑另一个方面中设置的过滤器.
为了显示:
[ ] All colors (18)
[x] Red (10)
[ ] Green (5)
[ ] Blue (3)
[ ] All notes (18)
[ ] Do (5)
[x] Re (7)
[ ] Mi (6)
Run Code Online (Sandbox Code Playgroud)
请注意,每个方面内的总计总和为查询的总命中数,就像没有设置过滤器一样.
我想要的行为是让Notes facet中的数字考虑到Colors facet中的过滤器,反之亦然.也就是说,注释术语的数字应该总和为10(以匹配红色滤波器),而不是18.
有趣的是,文档中的示例屏幕截图使用了Linked In中的一个示例,它实际上演示了我想要的行为.
http://www.elasticsearch.org/guide/reference/api/search/facets/
我能够通过为每个方面的每个术语手动重新提交一次查询来获得我想要的结果(呃)但是我想知道是否有办法通过更改我的查询获得与开箱即用的开箱即用相同的行为.