2016-07-24 198 views
0

以下映射在使用另一个字段对文档进行分组的文档的多个级别上汇总。Elasticsearch中GroupBy聚合的多个范围的总和

映射:

{ 
    'predictions': { 
     'properties': { 
       'Company':{'type':'string'}, 
       'TxnsId':{'type':'string'}, 
       'Emp':{'type':'string'}, 
       'Amount':{'type':'float'}, 
       'Cash/online':{'type':'string'}, 
       'items':{'type':'float'}, 
       'timestamp':{'type':'date'} 
      } 
      } 
     } 

我的要求是有点复杂,我需要

  1. 对于下每个EMP(获取不同的员工)
  2. 检查它是否是网上或套现交易
  3. 按范围类似0-10,11-20,21-30的项目....
  4. 总金额

最终输出是这样的:

>Emp-online-range-Amount  
>a-online-(0-10)-1240$  
>a-online-(21-30)-3543$  
>b-online-(0-10)-2345$  
>b-online-(11-20)-3456$ 
+0

什么是现金的'浮点值/ online'? – Val

回答

0

像这样的东西应该做的工作:

{ 
    "size": 0, 
    "aggs": { 
    "by_emp": { 
     "terms": { 
     "field": "Emp" 
     }, 
     "aggs": { 
     "cash_online": { 
      "filters": { 
      "filters": { 
       "cashed": { 
       "term": { 
        "Cash/online": "cached" 
       } 
       }, 
       "online": { 
       "term": { 
        "Cash/online": "online" 
       } 
       } 
      } 
      }, 
      "aggs": { 
      "ranges": { 
       "range": { 
       "field": "items", 
       "ranges": [ 
        { 
        "from": 0, 
        "to": 11 
        }, 
        { 
        "from": 11, 
        "to": 21 
        }, 
        { 
        "from": 21, 
        "to": 31 
        } 
       ] 
       }, 
       "aggs": { 
       "total": { 
        "sum": { 
        "field": "Amount" 
        } 
       } 
       } 
      } 
      } 
     } 
     } 
    } 
    } 
} 
+0

有没有这样的运气? – Val