請幫我找到一種機制來聚合以下域或證明它不存在於當前API中。在Elasticsearch中加入reverse_nested聚合
curl -XDELETE 127.0.0.1:9200/test_index
curl -XPUT 127.0.0.1:9200/test_index -d '{
"mappings": {
"contact": {
"properties": {
"facebook_profile": {
"type": "nested",
"properties": {
"education": {
"type": "string"
},
"year": {
"type": "integer"
}
}
},
"google_profile": {
"type": "nested",
"properties": {
"education": {
"type": "string"
},
"year": {
"type": "integer"
}
}
}
}
}
}
}'
curl -XPUT 127.0.0.1:9200/test_index/contact/contact1 -d '{
"google_profile": {
"education": "stanford", "year": 1990
}
}'
curl -XPUT 127.0.0.1:9200/test_index/contact/contact2 -d '
{
"facebook_profile": {
"education": "stanford", "year": 1990
}
}'
如何查詢ES以查找有關從特定大學畢業的聯繫人數量的統計數據?
我發現了一種可能性,但它並沒有給我想要的結果,因爲它不能對這個問題對於接觸回答以上,而只是其特定的配置文件(嵌套文檔):
curl -XPOST '127.0.0.1:9200/test_index/_search?search_type=count&pretty=true' -d '{
"aggs": {
"facebook_educations": {
"aggs": {
"field": {
"terms": {
"field": "contact.facebook_profile.education"
},
"aggs": {
"reverse": {
"reverse_nested": {
}
}
}
}
},
"nested": {
"path": "contact.facebook_profile"
}
},
"google_educations": {
"aggs": {
"field": {
"terms": {
"field": "contact.google_profile.education"
},
"aggs": {
"reverse": {
"reverse_nested": {
}
}
}
}
},
"nested": {
"path": "contact.google_profile"
}
}
}
}'
是什麼給了我:
"aggregations" : {
"facebook_educations" : {
"doc_count" : 1,
"field" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 0,
"buckets" : [ {
"key" : "stanford",
"doc_count" : 1,
"reverse" : {
"doc_count" : 1
}
} ]
}
},
"google_educations" : {
"doc_count" : 1,
"field" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 0,
"buckets" : [ {
"key" : "stanford",
"doc_count" : 1,
"reverse" : {
"doc_count" : 1
}
} ]
}
}
}
但在這裏我不能肯定,如果一個找到的聯繫人相同或不同的文檔(父),分別我不能回答我最初的問題。
謝謝你的任何建議。
你的第一個建議根本不起作用,因爲嵌套的文檔,你必須訪問_source領域。第二個選項可能會工作,但不幸的是不在我的情況下,因爲我已經將文檔嵌套到子文檔中,我嘗試執行某種has_parent聚合。這是我現在得到的http://stackoverflow.com/questions/35061945/match-query-inside-script-elasticsearch。不管怎樣,謝謝你 – Serj