两个相同级别的统计信息聚合

时间:2014-08-18 07:21:15

标签: elasticsearch

我们可以有两个相同级别的聚合吗?例如,我希望在一个存储桶聚合中有两个不同字段的两个统计信息聚合。我该怎么办呢?

1 个答案:

答案 0 :(得分:0)

好的,我得到了解决方案

{
  "size" : 0,
  "query" : {
    "filtered" : {
      "query" : {
        "match_all" : { }
      },
      "filter" : {
        "and" : {
          "filters" : [ {
            "numeric_range" : {
              "transactionDate" : {
                "from" : "2013-08-01",
                "to" : "2013-11-01",
                "include_lower" : true,
                "include_upper" : true
              }
            }
          }]
        }
      }
    }
  },
  "aggregations" : {
   "monthWise1" : {
     "date_range" : {
       "field" : "transactionDate",
       "ranges" : [ {
         "key" : "Aug-2013",
         "from" : "2013-08-01",
         "to" : "2013-08-31"
       }, {
         "key" : "Sep-2013",
         "from" : "2013-09-01",
         "to" : "2013-09-30"
       }, {
         "key" : "Oct-2013",
         "from" : "2013-10-01",
         "to" : "2013-10-31"
       } ]
     },
     "aggregations" : {
       "statField1" : {
         "stats": {
           "field": "balance"
         }
       },
       "statField2" : {
         "stats": {
           "field": "discount"
         }
       }
     }
  }
}
}