如何在elasticsearch中按查询编写组?

时间:2017-06-28 05:18:05

标签: mysql elasticsearch

这是我的Mysql查询:

SELECT * FROM `provider` WHERE  `active` = 'Y' GROUP BY `OfferID`, `offerName`, `duration`, `price`, `downloadSpeed`, `numChannels`  LIMIT 10;

现在转换为Elasticsearch查询,它可以工作,

GET /promoapp_version_1_1/providerofferpromotionmaster/_search` "query": {
           "bool": {
        "must": [

        { "match": { "active": "Y" } }
        ]
    },  "aggs": {
"group_by_val": {
  "terms": {
    "field": "offername.keyword"
  },

  "aggs": {
    "group_by_price": {
       "terms": {
         "field": "price"
      },

      "aggs":{
          "group_by_downloadspeed":{
              "terms":{
                  "field":"downloadspeed"
              },
           "aggs":{
              "group_by_duration":{
                    "terms":{
                      "field":"duration"
                    }
                }
           }
          }
      }
    }
  }
}
}
}`

如何在ES中按多个字段(offerName , ,价格, downloadSpeed , numChannels)编写分组

1 个答案:

答案 0 :(得分:0)

您希望此处使用的是来自elasticsearch的 sum aggregation 指标。聚合基本上将您的数据分组到类似组的桶中。