我有一个嵌套聚合和过滤器的问题,基本上没有过滤器它返回总和为全局范围但嵌套doc_count是好的,但总是0,这里是我试图运行的查询:ElasticSearch中的嵌套聚合和过滤器
{
"query": {
"nested": {
"path": "skills.tree",
"query": {
"bool" : {
"must" : [
{"match": {"leaf0": "Management"}},
{"match": {"leaf1": "Financial"}}
]
}
}
}
},
"aggs": {
"by_org": {
"terms": {
"field": "org"
},
"aggs": {
"sum_weight0-filtered": {
"filter": {
"nested": {
"path": "skills.tree",
"query": {
"bool" : {
"must" : [
{"match": {"leaf0": "Management"}},
{"match": {"leaf1": "Financial"}}
]
}
}
}
},
"aggs":{
"sum0":{
"sum": {
"field": "skills.tree.weight0"
}
},
"sum1":{
"sum": {
"field": "skills.tree.weight1"
}
}
}
}
}
}
}
}
和下面是一个示例输出:
{
"took": 978,
"timed_out": false,
"_shards": {
"total": 50,
"successful": 50,
"failed": 0
},
"hits": {
"total": 11337,
"max_score": 0,
"hits": []
},
"aggregations": {
"by_org": {
"buckets": [
{
"key": "Aetna",
"doc_count": 1888,
"sum_weight0-filtered": {
"doc_count": 1888,
"sum0": {
"value": 0
},
"sum1": {
"value": 0
}
}
},
{
"key": "AECOM",
"doc_count": 1085,
"sum_weight0-filtered": {
"doc_count": 1085,
"sum0": {
"value": 0
},
"sum1": {
"value": 0
}
}
}
....
,这里是部分的模式:
'skills' => array(
'properties' => array(
'tree' => array(
'type' => 'nested',
'properties' => array(
'leaf0' => array(
"type" => "multi_field",
"fields" => array(
"leaf0"=> array(
"type" => "string",
"index" => "not_analyzed"
),
"search" => array(
"type" => "string",
"index" => "analyzed"
)
)
),
'leaf1' => array(
"type" => "multi_field",
"fields" => array(
"leaf1"=> array(
"type" => "string",
"index" => "not_analyzed"
),
"search" => array(
"type" => "string",
"index" => "analyzed"
)
)
),
'leaf2' => array(
"type" => "multi_field",
"fields" => array(
"leaf2"=> array(
"type" => "string",
"index" => "not_analyzed"
),
"search" => array(
"type" => "string",
"index" => "analyzed"
)
)
),
'leaf3' => array(
"type" => "multi_field",
"fields" => array(
"leaf3"=> array(
"type" => "string",
"index" => "not_analyzed"
),
"search" => array(
"type" => "string",
"index" => "analyzed"
)
)
),
'leaf4' => array(
"type" => "multi_field",
"fields" => array(
"leaf4"=> array(
"type" => "string",
"index" => "not_analyzed"
),
"search" => array(
"type" => "string",
"index" => "analyzed"
)
)
),
'leaf5' => array(
"type" => "multi_field",
"fields" => array(
"leaf5"=> array(
"type" => "string",
"index" => "not_analyzed"
),
"search" => array(
"type" => "string",
"index" => "analyzed"
)
)
),
'weight1' => array(
'type' => 'integer',
),
'weight2' => array(
'type' => 'integer',
),
'weight3' => array(
'type' => 'integer',
),
'weight4' => array(
'type' => 'integer',
),
'weight5' => array(
'type' => 'integer',
)
)
)
问题在于sum0和sum1它们都返回0,尽管数值在那里(它适用于更高范围(无过滤器))。我在这里做错了什么?
谢谢,但对于初学者你有语法错误,nestedAgg应该有1个更多的层次称为“嵌套”,然后包装所有下面说,它仍然无法正常工作,我的意思是总结所有数字,但从全球范围,所以它忽略“领域”:“组织”的范围,而不是在每个组织内部总结出去,这是我的原始问题。 – Marcin 2015-02-24 11:58:52
请现在试试。所做的更改 – 2015-02-24 13:37:24
还是不对的,基本上聚集针对完整的索引上运行,而不是水桶: ' “聚合”:{ “by_org”:{ “桶”: { “钥匙”: “本公司”, “ doc_count “:3171, ”sum_weight0过滤“:{ ”doc_count“:3171, ”nestedAgg“:{ ”doc_count“:60117, ”SUM0“:{ ”值“:343885 }, ” sum1“:{ ”value“:93162 } }' – Marcin 2015-02-24 16:59:33