目前我有以下映射:
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')
)
)
)
)
)
)
);
我想查询产品 . 并让ElasticSearch返回聚合的规范 . 但对于每个specs.id一个包含所有值的桶 . 只有在可见的情况下才是真的 .
"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
},
]
}
}
不知道数据集中的规范ID .
这可能吗?
1 回答
您是否尝试在路径规范和字段属性上执行嵌套术语聚合 . 这应该创建具有不同ID的规则和规格具有相同ID的文档将落在相同的存储桶中 . 对可见性执行过滤器聚合将过滤掉所有可见性为false的文档 . 现在,您可以对值进行术语聚合,作为过滤器聚合的子聚合,以获得所需的输出 .