【问题标题】:Elasticsearch not showing correct data for SQL apiElasticsearch 没有为 SQL api 显示正确的数据
【发布时间】:2019-12-25 17:39:40
【问题描述】:

es 版本:6.7

您好,我正在使用 elasticsearch sql api 我发现添加 DISTINCT 时结果不正确

es 代码

require('./elasticsearch/').transport.request({
        method : "POST",
        path   : '/_xpack/sql',
        body : {
            query : "SELECT COUNT(DISTINCT id)  FROM orders"
        }  
    },(err,res) => {
        console.log("error",err)
        return res.status(200).send(res)
    })

结果:

{
   "columns":[{"name":"COUNT(DISTINCT id)","type":"long"}],
    "rows":[[11459]] <----------------------------------------------- MUST BE (11501)
}

我在 mysql 中执行相同的查询

SELECT COUNT(DISTINCT id)  FROM orders

结果

11501

任何帮助? 谢谢

【问题讨论】:

标签: elasticsearch


【解决方案1】:

根据ES成员

来自 SQL 的 COUNT(DISTINCT) 在后台使用基数聚合,根据设计,在所有情况下都不能提供准确的结果

https://github.com/elastic/elasticsearch/issues/50354

所以基本上你应该使用 DSL 而不是 SQL API

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-18
    • 1970-01-01
    • 2011-06-05
    • 1970-01-01
    • 2020-06-13
    • 1970-01-01
    • 2016-08-09
    • 1970-01-01
    相关资源
    最近更新 更多