Skip to content

When running geo_line aggregation, the sort_order has no effect #94733

@craigtaverner

Description

@craigtaverner

Elasticsearch Version

all supported versions

Installed Plugins

No response

Java Version

bundled

OS Version

MacOSX (Darwin Kernel Version 22.3.0 arm64)

Problem Description

The documentation for geo_line claims that the option sort_order can be either ASC (default) or DESC:

This option accepts one of two values: "ASC", "DESC".
The line is sorted in ascending order by the sort key when set to "ASC", and in descending with "DESC".

However, when testing this, no matter which you choose the actual order of points in the result is always ASC by the value of the sort field.

Steps to Reproduce

Create an index with a geo_point and a

PUT /locations
{
  "mappings": {
    "properties": {
      "location":    { "type": "geo_point" },
      "rank":  { "type": "double"  }
    }
  }
}

Add data with appropriate rank values:

POST /locations/_bulk?refresh
{"index":{}}
{"location": [13.37139831, 47.82930284], "rank": 2.0 }
{"index":{}}
{"location": [13.3784208402, 47.88832084022], "rank": 0.0 }
{"index":{}}
{"location": [13.371830148701, 48.2084200148], "rank": 1.2 }

Query with ASC sort order:

POST /locations/_search?filter_path=aggregations
{
  "aggs": {
    "line": {
      "geo_line": {
        "point": {"field": "location"},
        "sort": {"field": "rank"},
        "include_sort": true,
        "sort_order": "ASC"
      }
    }
  }
}

And get expected result:

{
  "aggregations": {
    "line": {
      "type" : "Feature",
      "geometry" : {
        "type" : "LineString",
        "coordinates" : [
          [
            13.378421,
            47.888321
          ],
          [
            13.37183,
            48.20842
          ],
          [
            13.371398,
            47.829303
          ]
        ]
      },
      "properties" : {
        "complete" : true,
        "sort_values": [0.0, 1.2, 2.0]
      }
    }
  }
}

Query with DESC sort order:

POST /locations/_search?filter_path=aggregations
{
  "aggs": {
    "line": {
      "geo_line": {
        "point": {"field": "location"},
        "sort": {"field": "rank"},
        "include_sort": true,
        "sort_order": "DESC"
      }
    }
  }
}

But you get exactly the same result as the previous query. However, we expect the sort order to have been reversed and we expect the following result instead:

{
  "aggregations": {
    "line": {
      "type" : "Feature",
      "geometry" : {
        "type" : "LineString",
        "coordinates" : [
          [
            13.371398,
            47.829303
          ],
          [
            13.37183,
            48.20842
          ],
          [
            13.378421,
            47.888321
          ]
        ]
      },
      "properties" : {
        "complete" : true,
        "sort_values": [2.0, 1.2, 0.0]
      }
    }
  }
}

Logs (if relevant)

No response

Metadata

Metadata

Assignees

Labels

:Analytics/GeoIndexing, search aggregations of geo points and shapes>bugTeam:AnalyticsMeta label for analytical engine team (ESQL/Aggs/Geo)

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions