Skip to content

SQL provides incorrect results when sorting by an aggregation and using LIMIT #40984

@alexfrancoeur

Description

@alexfrancoeur

Elasticsearch version (bin/elasticsearch --version):
7.0.0-rc1

Plugins installed: []
none

JVM version (java -version):

java version "1.8.0_121"
Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)

OS version (uname -a if on a Unix-like system):
Darwin Alexs-MacBook-Pro-2.local 18.5.0 Darwin Kernel Version 18.5.0: Mon Mar 11 20:40:32 PDT 2019; root:xnu-4903.251.3~3/RELEASE_X86_64 x86_64

Description of the problem including expected versus actual behavior:
In Canvas I"m running the following query

SELECT source.geo.country_iso_code country, count(*) total
FROM "filebeat-*"
GROUP BY country
ORDER BY total desc

and getting

image (28)

When I run the following query

SELECT source.geo.country_iso_code country, count(*) total
FROM "filebeat-*"
GROUP BY country
ORDER BY total desc
LIMIT 5

I'd expect to get US, IT, FR, DE, MX but instead I get

image (29)

Translate returns

{
  "size" : 0,
  "_source" : false,
  "stored_fields" : "_none_",
  "aggregations" : {
    "groupby" : {
      "composite" : {
        "size" : 5,
        "sources" : [
          {
            "164180" : {
              "terms" : {
                "field" : "source.geo.country_iso_code",
                "missing_bucket" : true,
                "order" : "asc"
              }
            }
          }
        ]
      }
    }
  }
}

This seems to be a bug with LIMIT and ordering by an aggregation

cc: @astefan @costin

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions