我有一個嵌套聚合和過濾器的問題,基本上沒有過濾器它返回總和爲全局範圍但嵌套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