我需要有關彈性搜索的統計資訊。我無法提出要求。
我想知道每次預約的人數。
約會索引映射
{
"id" : "383577",
"persons" : [
{
"id" : "1",
},
{
"id" : "2",
}
]
}
我想要什么
"buckets" : [
{
"key" : "1", <--- appointment of 1 person
"doc_count" : 1241891
},
{
"key" : "2", <--- appointment of 2 persons
"doc_count" : 10137
},
{
"key" : "3", <--- appointment of 3 persons
"doc_count" : 8064
}
]
謝謝
uj5u.com熱心網友回復:
最簡單的方法是創建另一個包含persons陣列長度并在該欄位上聚合的整數欄位。
{
"id" : "383577",
"personsCount": 2, <---- add this field
"persons" : [
{
"id" : "1",
},
{
"id" : "2",
}
]
}
實作您期望的非最佳方法是使用將persons動態回傳陣列長度的腳本,但請注意,這是次優的,并且可能會根據您擁有的資料量損害您的集群:
GET /_search
{
"aggs": {
"persons": {
"terms": {
"script": "doc['persons.id'].size()"
}
}
}
}
如果您想更新所有檔案以創建該欄位,您可以這樣做:
POST index/_update_by_query
{
"script": {
"source": "ctx._source.personsCount = ctx._source.persons.length"
}
}
但是,您還需要修改索引應用程式的邏輯以創建該新欄位。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/437769.html
標籤:弹性搜索
