2017-08-07 69 views
0

我我的PHP MySQL的应用程序转换为Elasticsearch, 这里是我的PHP MySQL查询以及如何这个查询写入Elasticseach(5.5版)怎么办我写的MySQL不同的查询Elasticesearch

我试着写聚集,但结果数量从旧版本的MySQL结果数量不匹配。

SELECT COUNT(DISTINCT offerName, `OfferID`, `duration`, `price`, `numChannels`, providerName) AS "totalRecords" FROM `video` WHERE `active` = 'Y' 

这里是我的Elasticsearch查询:

{ 
"size": 0, 
"query": 

     { "bool": { 
      "should": [ 
        { "match": { "active": "Y" }} 
       ] 
      } 
     }, 
"aggs": { 
    "count_by_OfferID": { 
     "terms": { 
      "field": "offerID" 
     } 
    }, 
    "count_by_offerName":{ 
      "terms": { 
      "field": "offerName" 
     } 
    }, 
    "count_by_duration":{ 
     "terms": { 
      "field": "duration" 
     } 
    }, 
    "count_by_price":{ 
     "terms": { 
      "field": "price" 
     } 
    }, 
     "count_by_downloadSpeed":{ 
     "terms": { 
      "field": "downloadSpeed" 
     } 
    }, 
    "count_by_numChannels":{ 
     "terms": { 
      "field": "numChannels" 
     } 
    }, 
     "count_by_providerName":{ 
     "terms": { 
      "field": "providerName" 
     } 
    } 
     } 

} 
+0

发表您的聚集请 – aclokay

+0

你能在这里发表您elasticQuery? – sourabh1024

+0

我有更新我的elasticsearch查询时,请检查一下,这写查询方式ES获得不同的值,或者是有任何其他方式? –

回答

1

也许你应该修改您的映射,使您可以更有效地得到答案,但Elasticsearch的DISTINCT COUNT被称为cardinality聚集,并支持特设scripting。我希望我能正确理解你的问题。

基数度量标准支持脚本,但有明显的性能问题,但是因为散列需要随时计算。