2017-06-28 40 views
0

這裏是我的MySQL查詢:如何在elasticsearch中通過查詢編寫組?

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" 
        } 
       } 
      } 
      } 
     } 
    } 
    } 
} 
} 
}` 

,以及如何編寫由多個字段組(offerName ,時間,價格, downloadSpeed , numChannels )in ES

回答

0

你想在這裏使用的是sum aggregation metricsearch from elasticsearch。聚合基本上將您的數據分組到相似組的桶中。

+0

我試過聚合,聚合給予特定字段中的計數數目是在查詢結果之後。 –

+0

你能否詳細說明你的評論? –

+0

我更新我的查詢,我在ES嘗試,請參閱上面的查詢 –