# Geo\_distance agg results not consistent

**URL:** <https://discuss.elastic.co/t/geo-distance-agg-results-not-consistent/311453>\
**Category:** Elasticsearch\
**Created:** [August 4, 2022, 5:55pm UTC](https://discuss.elastic.co/t/geo-distance-agg-results-not-consistent/311453 "2022-08-04T17:55:47Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![drfreed](https://avatars.discourse-cdn.com/v4/letter/d/e9bcb4/32.png) [@drfreed](https://discuss.elastic.co/u/drfreed)\
**Post date:** [August 4, 2022, 5:55pm UTC](https://discuss.elastic.co/t/geo-distance-agg-results-not-consistent/311453/1 "2022-08-04T17:55:47Z")

</div>

I was trying out the geo\_distance aggreation and received different results based on the order of the ranges specified. I was able to replicate this using the example in the geo\_distance aggregation documentation page.

```auto
PUT /museums
{
  "mappings": {
    "properties": {
      "location": {
        "type": "geo_point"
      }
    }
  }
}

POST /museums/_bulk?refresh
{"index":{"_id":1}}
{"location": "POINT (4.912350 52.374081)", "name": "NEMO Science Museum"}
{"index":{"_id":2}}
{"location": "POINT (4.901618 52.369219)", "name": "Museum Het Rembrandthuis"}
{"index":{"_id":3}}
{"location": "POINT (4.914722 52.371667)", "name": "Nederlands Scheepvaartmuseum"}
{"index":{"_id":4}}
{"location": "POINT (4.405200 51.222900)", "name": "Letterenhuis"}
{"index":{"_id":5}}
{"location": "POINT (2.336389 48.861111)", "name": "Musée du Louvre"}
{"index":{"_id":6}}
{"location": "POINT (2.327000 48.860000)", "name": "Musée d'Orsay"}

```

And then submit the following two queries...

```auto
POST /museums/_search?size=0
{
  "aggs": {
    "rings_around_amsterdam": {
      "geo_distance": {
        "field": "location",
        "origin": "POINT (4.894 52.3760)",
        "ranges": [
          { "to": 100000 },
          { "from": 100000, "to": 300000 },
          { "from": 300000 }
        ]
      }
    }
  }
}

```

I get document counts in my agg buckets of 3, 1, and 2.

If I change just the order of the ranges in the query to this:

```auto
POST /museums/_search?size=0
{
  "aggs": {
    "rings_around_amsterdam": {
      "geo_distance": {
        "field": "location",
        "origin": "POINT (4.894 52.3760)",
        "ranges": [
          { "from": 100000, "to": 300000 },
          { "from": 300000 },
          { "to": 100000 }
        ]
      }
    }
  }
}

```

I get document counts in my agg buckets of 1, 2, and 0.

I was thinking the order of the ranges would not matter. Am I missing something?

---

<div class="post-metadata">

**Author:** ![Ignacio\_Vera](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ignacio_vera/32/36674_2.png) [@Ignacio\_Vera](https://discuss.elastic.co/u/Ignacio_Vera)\
**Post date:** [August 5, 2022, 6:07am UTC](https://discuss.elastic.co/t/geo-distance-agg-results-not-consistent/311453/2 "2022-08-05T06:07:15Z")

</div>

Hi @drfreed!

Welcome to the community, this is clearly a bug, results should be independent of the ordering of the provided ranges. Would you mind opening a bug report in the Elasticsearch [repository](https://github.com/elastic/elasticsearch)?

---

<div class="post-metadata">

**Author:** ![drfreed](https://avatars.discourse-cdn.com/v4/letter/d/e9bcb4/32.png) [@drfreed](https://discuss.elastic.co/u/drfreed)\
**Post date:** [August 5, 2022, 12:45pm UTC](https://discuss.elastic.co/t/geo-distance-agg-results-not-consistent/311453/3 "2022-08-05T12:45:31Z")

</div>

Sure, I will put one in... thanks!

---

<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:** [September 2, 2022, 12:46pm UTC](https://discuss.elastic.co/t/geo-distance-agg-results-not-consistent/311453/4 "2022-09-02T12:46:13Z")

</div>

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