Geo Location sorting doesn't seem to work

Hi, I'm trying to sort by location. Similar data and tests work correctly in Elastic Search but fail using Elastic App Search (latest 8.3 version). The results should be in the following order "Item-2, Item-3, Item-1", instead they are in this order "Item-1, Item-2, Item-3".

Request body:

{
  "query": "",
  "sort": {
    "location": {
      "center": [
        0,
        14
      ],
      "order": "asc"
    }
  },
  "page": {
    "size": 10,
    "current": 1
  }
}

Response body

{
  "meta": {
    "alerts": [],
    "warnings": [],
    "precision": 2,
    "engine": {
      "name": "test-core-item",
      "type": "default"
    },
    "page": {
      "current": 1,
      "total_pages": 1,
      "total_results": 6,
      "size": 10
    },
    "request_id": "c8f5aaaa71d9f152f203f5effd995031"
  },
  "results": [
    {
      "location": {
        "raw": "0.0,0.0"
      },
      "_meta": {
        "id": "Item-1",
        "engine": "test-core-item",
        "score": null
      },
      "id": {
        "raw": "Item-1"
      }
    },
    {
      "location": {
        "raw": "0.0,10.0"
      },
      "_meta": {
        "id": "Item-2",
        "engine": "test-core-item",
        "score": null
      },
      "id": {
        "raw": "Item-2"
      }
    },
    {
      "location": {
        "raw": "0.0,20.0"
      },
      "_meta": {
        "id": "Item-3",
        "engine": "test-core-item",
        "score": null
      },
      "id": {
        "raw": "Item-3"
      }
    }
  ]
}

This seems like a pretty major bug in the app search. How does anyone use it with GEO location?

Hi Woland,

Geolocation raw data can be repsesented in different ways, e.g. as a string of "<lat>, <lon>" or as an array with elements [<lon>, <lat>] (see docs).

Please mind the difference in the order of coordinates and either pass

  • "center": [14, 0] or
  • "center": "0, 14"

Example request:

{
    "query": "",
    "sort": {
        "location": {
            "center": [
                14,
                0
            ],
            "order": "asc"
        }
    }
}

Response (with results ordered as item-2, item-3, item-1 as expected):

{
    ...
    "results": [
        {
            "location": {
                "raw": "0.0, 10.0"
            },
            "id": {
                "raw": "item-2"
            },
            "_meta": {
                "id": "item-2",
                "engine": "geoloc-sort-test",
                "score": null
            },
            "title": {
                "raw": "Item 2"
            }
        },
        {
            "location": {
                "raw": "0.0, 20.0"
            },
            "id": {
                "raw": "item-3"
            },
            "_meta": {
                "id": "item-3",
                "engine": "geoloc-sort-test",
                "score": null
            },
            "title": {
                "raw": "Item 3"
            }
        },
        {
            "location": {
                "raw": "0.0, 0.0"
            },
            "id": {
                "raw": "item-1"
            },
            "_meta": {
                "id": "item-1",
                "engine": "geoloc-sort-test",
                "score": null
            },
            "title": {
                "raw": "Item 1"
            }
        }
    ]
}

Thanks for pointing that out! Didn't realize order was different in those two formats, even though I even read the same documentation (thought it was more focused on making sure we index and pass parameters in the same order).