【问题标题】:How to do i write mysql distinct query to Elasticesearch如何将 mysql distinct 查询写入 Elasticsearch
【发布时间】:2018-01-14 08:50:41
【问题描述】:

我正在将我的 PHP MySQL 应用程序转换为 Elasticsearch, 这是我的 PHP MySQL 查询以及如何将此查询写入 Elasticseach(5.5 版)

我尝试编写聚合,但结果计数与旧 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"
        }
     }
        }

}

【问题讨论】:

  • 请发布您的汇总
  • 你可以在这里发布你的 elasticQuery 吗?
  • 我已经更新了我的 elasticsearch 查询,请检查一下,这是编写查询以在 ES 中获取不同值的方式还是有其他方式?

标签: php mysql elasticsearch


【解决方案1】:

也许你应该修改你的映射以便更有效地得到答案,但是 Elasticsearch 的 DISTINCT COUNT 被称为 cardinality 聚合,它支持 ad-hoc scripting。希望我正确理解了您的问题。

基数指标支持脚本,但由于需要动态计算哈希,因此性能受到明显影响。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-02
    • 2016-01-30
    • 2021-07-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多