0
在我開發的培訓模塊中,有一個頁面將所有課程列入帶可篩選標題的表格視圖。其中一列是「已保存」列,如果我加了書籤,它將被「保存」,如果沒有,則會被保存爲「未保存」。Elasticsearch自定義聚合結果
課程實體索引如下:
{
"_index": "myindex",
"_type": "course",
"_id": "248fc0a2-06e1-11e6-b740-000c298fdb4d",
"_score": 1,
"_source": {
"boost_number": 1,
"entity_type_number": 64,
"course_status_string": "Closed",
"title": "My Test Course",
"body": "This is just a test course",
"created_date": "20160420T101753Z",
"categories_uuid": [ ],
"segment_string": [
"Other"
],
"vertical_string": [
"Other"
],
"saved_users_uuid": [
"251bde26-4adf-11e4-b705-000c298fdb4d",
"00026884-7cc8-11e3-a570-fa163e2bcb7a",
"00061164-9283-11e5-a394-000c298fdb4d",
"00110a72-0b8b-11e4-9a64-fa163e2bcb7a",
]
}
比方說,我曾與ID登錄: 「251bde26-4adf-11e4-b705-000c298fdb4d」。 當查詢彈性方面,我收到此鬥:
"saved_users" : {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets" : [
{
"key" : "251bde26-4adf-11e4-b705-000c298fdb4d",
"doc_count" : 5
},
{
"key" : "00026884-7cc8-11e3-a570-fa163e2bcb7a",
"doc_count" : 0
},
...
]
}
不過,我想有其他自定義鬥如:
{
...
"buckets": [
{
"key": "Saved",
"doc_count": ...
},
{
"key": "Unsaved",
"doc_count": ...
},
]
}
這可能嗎?我怎麼能這樣做?