亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

如何對篩選以后聚合分組后的數據再進行范圍查詢呢?

老師好,項目中需要用到es來實現數據統計,現在有這樣一個需求不知道該如何實現,查了一下資料,也沒有看到好的解決辦法

現在有這樣一組數據

[

{userId:1, name: 'liu', createTime:'2017-9-16', investMount: 1000, sex: 1},

{userId:1, name: 'liu', createTime:'2017-9-16', investMount: 2000, sex: 1},

{userId:1, name: 'liu', createTime:'2017-9-16', investMount: 3000, sex: 1},

{userId:2, name: 'wang', createTime:'2017-10-1', investMount: 1500, sex: 0},

{userId:3, name: 'zhang', createTime:'2017-10-14', investMount: 1800, sex: 1},

{userId:4, name: 'zhao', createTime:'2017-10-17', investMount: 4000, sex: 1}

]

比如:現在想查詢注冊時間(createTime)是2017-9-15到2017-10-15日之間,投資總額(同一個userId用戶investMount的總和)在2000-5000之間的男性(sex==1)的用戶,最后取到符合條件的userId的集合,這種需求該如何寫DSL語句呢?

我現在對es的學習能力只能想到這一步,先根據固定的條件進行查詢篩選,然后再根據用戶id進行分組,查詢每個用戶的投資總金額,但是如何使最后結果能返回符合所有條件的用戶userId的集合我還是想不出來,求指教~~

{

"query": {

"bool": {

"must": {

{"term": {"sex": 1}}

},

"filter": {

"range": {

"createTime": {

"from": "2017-9-15",

"to": "2017-10-15"

}

}

}

}

},

"aggs": {

"group_by_userId": {

"terms": {"field": "userId"},

"aggs": {

"sum_investMount": {

"sum": { "field": "investMount"}

}

}

}

}

}


正在回答

1 回答

{

"query": {

"bool": {

"must": {

{"term": {"sex": 1}}

},

"filter": {

"range": {

"userId": {

"from": "1",

"to": "2

}

}

}

}

},

"aggs": {

"group_by_userId": {

"terms": {"field": "userId"},

"aggs": {

"sum_investMount": {

"sum": { "field": "investMount"}

}

}

}

}

}


0 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

如何對篩選以后聚合分組后的數據再進行范圍查詢呢?

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號