这是我的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 , duration , price , downloadSpeed , numChannels)

最佳答案

您要在此处使用的是elasticsearch的sum aggregation指标。聚合基本上将您的数据分为相似组的存储桶。

07-24 15:24