# Geo Location sorting doesn't seem to work

**URL:** <https://discuss.elastic.co/t/geo-location-sorting-doesnt-seem-to-work/311023>\
**Category:** Elastic Search\
**Tags:** elastic-app-search\
**Created:** [July 29, 2022, 11:46pm UTC](https://discuss.elastic.co/t/geo-location-sorting-doesnt-seem-to-work/311023 "2022-07-29T23:46:51Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Woland](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/woland/32/101616_2.png) [@Woland](https://discuss.elastic.co/u/Woland)\
**Post date:** [July 29, 2022, 11:46pm UTC](https://discuss.elastic.co/t/geo-location-sorting-doesnt-seem-to-work/311023/1 "2022-07-29T23:46:51Z")

</div>

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:

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

```

Response body

```auto
{
  "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"
      }
    }
  ]
}

```

---

<div class="post-metadata">

**Author:** ![Woland](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/woland/32/101616_2.png) [@Woland](https://discuss.elastic.co/u/Woland)\
**Post date:** [August 2, 2022, 4:03pm UTC](https://discuss.elastic.co/t/geo-location-sorting-doesnt-seem-to-work/311023/2 "2022-08-02T16:03:59Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![demjened](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/demjened/32/109159_2.png) [@demjened](https://discuss.elastic.co/u/demjened)\
**Post date:** [August 2, 2022, 4:19pm UTC](https://discuss.elastic.co/t/geo-location-sorting-doesnt-seem-to-work/311023/3 "2022-08-02T16:19:07Z")

</div>

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](https://www.elastic.co/guide/en/app-search/current/api-reference.html#overview-api-references-geolocation)).

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

- `"center": [14, 0]` or
- `"center": "0, 14"`

Example request:

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

```

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

```auto
{
    ...
    "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"
            }
        }
    ]
}

```

---

<div class="post-metadata">

**Author:** ![Woland](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/woland/32/101616_2.png) [@Woland](https://discuss.elastic.co/u/Woland)\
**Post date:** [August 2, 2022, 8:40pm UTC](https://discuss.elastic.co/t/geo-location-sorting-doesnt-seem-to-work/311023/4 "2022-08-02T20:40:36Z")

</div>

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).

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [August 30, 2022, 8:41pm UTC](https://discuss.elastic.co/t/geo-location-sorting-doesnt-seem-to-work/311023/5 "2022-08-30T20:41:18Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
