elasticsearch,Mysql,elasticsearch" /> elasticsearch,Mysql,elasticsearch" />

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

Mysql 如何在elasticsearch中按查询编写分组?,mysql,elasticsearch,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` "

下面是我的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
NumChannel)编写分组,这里要使用的是elasticsearch的度量。聚合基本上将您的数据分组到相似组的存储桶中。

我尝试过聚合,聚合给出特定字段中的计数数是在查询结果之后。您能详细说明您的评论吗?我更新了我在ES中尝试过的查询,请参阅上面的查询