我有一個ElasticSearch索引,用於存儲電話事務(SMS,MMS,Calls等)及其相關成本。通過字符串數組進行Elasticsearch聚合
這些文檔的關鍵是MSISDN(MSISDN =電話號碼)。在我的應用程序中,我知道有一組用戶。每個用戶可以有一個或多個MSISDN。
下面是這種文件的映射:
"mappings" : {
"cdr" : {
"properties" : {
"callDatetime" : {
"type" : "long"
},
"callSource" : {
"type" : "string"
},
"callType" : {
"type" : "string"
},
"callZone" : {
"type" : "string"
},
"calledNumber" : {
"type" : "string"
},
"companyKey" : {
"type" : "string"
},
"consumption" : {
"properties" : {
"data" : {
"type" : "long"
},
"voice" : {
"type" : "long"
}
}
},
"cost" : {
"type" : "double"
},
"country" : {
"type" : "string"
},
"included" : {
"type" : "boolean"
},
"msisdn" : {
"type" : "string"
},
"network" : {
"type" : "string"
}
}
}
}
我的目標和問題:
我的目標是使檢索通過成本通過CALLTYPE查詢組。但是,組只在我的PostgreSQL數據庫中不在ElasticSearch中表示。
所以我會檢索所有的MSISDN爲每個現有組的方法,並得到類似的字符串數組的列表,其中包含每個組中的每個MSISDN。
比方說,我有這樣的事情:
"msisdn_by_group" : [
{
"group1" : ["01111111111", "02222222222", "033333333333", "044444444444"]
},
{
"group2" : ["05555555555","06666666666"]
}
]
現在,我將用它來生成Elasticsearch查詢。我想用匯總(總成本)來計算不同桶中所有這些術語的總和,然後再通過callType分割它。 (製作一個疊式條形圖)。
我已經試過幾件事情,但沒有管理,使其工作(直方圖,水桶,期限和金額,主要是我與打關鍵字)。
如果有人在這裏可以幫助我的訂單,以及關鍵字,我可以用它來實現這一點,那將是巨大的:)謝謝
編輯: 這是我最後一次嘗試: QUERY:
{
"aggs" : {
"cost_histogram": {
"terms": {
"field": "callType"
},
"aggs": {
"cost_histogram_sum" : {
"sum": {
"field": "cost"
}
}
}
}
}
}
我去了預期的結果,但它缺少「組」分裂,因爲我不知道如何通過MSISDN數組作爲一個標準:
結果:
"aggregations": {
"cost_histogram": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "data",
"doc_count": 5925,
"cost_histogram_sum": {
"value": 0
}
},
{
"key": "sms_mms",
"doc_count": 5804,
"cost_histogram_sum": {
"value": 91.76999999999995
}
},
{
"key": "voice",
"doc_count": 5299,
"cost_histogram_sum": {
"value": 194.1196
}
},
{
"key": "sms_mms_plus",
"doc_count": 35,
"cost_histogram_sum": {
"value": 7.2976
}
}
]
}
}
也許顯示您現在的查詢並解釋仍然缺少的內容? – Val
@Val當然我忘了,我的壞!請參閱我的編輯請 – Alex
您需要另外一個「術語」聚合來包裝您當前的一個。 – Val