问题描述
目前我有以下映射:
array(
'index' => 'my_index',
'body' => array(
'mappings' => array(
'products' => array(
'_source' => array('enabled' => false),
'properties' => array(
'id' => array('type' => 'integer'),
'active' => array('type' => 'boolean'),
'specs' => array(
'type' => 'nested',
'properties' => array(
'id' => array('type' => 'integer'),
'value' => array('type' => 'text'),
'visible' => array('type' => 'boolean')
)
)
)
)
)
)
);
我想查询产品。
并且弹性搜索返回规格聚合。但是对于每个specs.id一个具有所有值的bucket。
只有在可见的情况下才是真的。
I would like to query the products.And have ElasticSearch return the specifications aggregated. But for each specs.id a bucket with all the values.And only if visible is true.
"aggregations": {
"specs_2": {
"buckets": [
{
"key": "Yes",
"doc_count": 90
},
{
"key": "No",
"doc_count": 80
},
]
},
"specs_4": {
"buckets": [
{
"key": "Yes",
"doc_count": 190
},
{
"key": "No",
"doc_count": 180
},
]
}
}
不知道数据集中的规范ids。
Without knowing the specification ids that are in the data set.
这可能吗?
推荐答案
您是否尝试在路径规范和字段properties.id上进行嵌套术语聚合?这应该创建具有不同ids和规格的桶具有相同ID的文档将落在相同的桶中。在可见性上执行过滤器聚合将过滤掉具有可见性false的所有文档。现在,您可以将值汇总作为过滤器聚合的子聚合,以获得所需的输出。
Have you tried doing a nested term aggregation on path specs and field properties.id ? This should create buckets with different ids and specs docs having same id will fall in same buckets. Doing a filter aggregation on visibility will filter out all docs with visibility false. Now you can do a term aggregation on value as sub-aggregation of filter aggregation to get the desired output.
这篇关于ElasticSearch动态桶聚合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!