# GeoDistance Aggregation is not working with Nested Aggregation

**URL:** <https://discuss.elastic.co/t/geodistance-aggregation-is-not-working-with-nested-aggregation/26012>\
**Category:** Elasticsearch\
**Created:** [July 21, 2015, 6:58pm UTC](https://discuss.elastic.co/t/geodistance-aggregation-is-not-working-with-nested-aggregation/26012 "2015-07-21T18:58:46Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ayushsangani](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ayushsangani/32/9612_2.png) [@ayushsangani](https://discuss.elastic.co/u/ayushsangani)\
**Post date:** [July 21, 2015, 6:58pm UTC](https://discuss.elastic.co/t/geodistance-aggregation-is-not-working-with-nested-aggregation/26012/1 "2015-07-21T18:58:46Z")

</div>

Hello all,

I'm using GeoDistance Aggregation on a nested field so it is wrapped around a nested aggregation. This query is being run ES 1.6.0 and encountering an exception which I'm unable to solve. Please also take a look at the query if it is the right way to use GeoDistance Aggregation.

Query:

```
 {
   "aggs": {
      "nested_geodistance": {
         "nested": {
            "path": "addresses"
         },
         "aggs": {
            "per_ring": {
               "geo_distance": {
                  "field": "addresses.location",
                  "unit": "km",
                  "orgin": {
                     "lat": 56.78,
                     "lon": -12.34
                  },
                  "ranges": [
                     {
                        "from": 100,
                        "to": 200
                     }
                  ]
               }
            }
         }
      }
   }
}

```

After executing this query I'm getting below exception:

> Parse Failure [Unexpected token START\_OBJECT in [per\_ring].]]; }{[F8SeZ5RjR\_KpSnvWBOSg7w][prod-contacts-0][4]: RemoteTransportException

I have revisited my query multiple times but unable to figure out what's wrong with my aggregation name.  
Please let me know if further information is needed.

Thanks,  
Ayush

---

<div class="post-metadata">

**Author:** ![colings86](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/colings86/32/44960_2.png) [@colings86](https://discuss.elastic.co/u/colings86)\
**Post date:** [July 22, 2015, 7:50am UTC](https://discuss.elastic.co/t/geodistance-aggregation-is-not-working-with-nested-aggregation/26012/2 "2015-07-22T07:50:22Z")

</div>

> [@ayushsangani](#):
>
> orgin

This is the issue. This should be `origin`. Not sure why the error is so cryptic though. I've raised a bug to fix the error message to be something more helpful: [Cryptic error message when mis-spelling a field in geo-distance aggregation · Issue #12391 · elastic/elasticsearch · GitHub](https://github.com/elastic/elasticsearch/issues/12391)

---

<div class="post-metadata">

**Author:** ![ayushsangani](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ayushsangani/32/9612_2.png) [@ayushsangani](https://discuss.elastic.co/u/ayushsangani)\
**Post date:** [July 22, 2015, 1:59pm UTC](https://discuss.elastic.co/t/geodistance-aggregation-is-not-working-with-nested-aggregation/26012/3 "2015-07-22T13:59:27Z")

</div>

Wow..!! I wonder how I missed that.  
Thank you Colin

---

<div class="post-metadata">

**Author:** ![colings86](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/colings86/32/44960_2.png) [@colings86](https://discuss.elastic.co/u/colings86)\
**Post date:** [July 22, 2015, 2:27pm UTC](https://discuss.elastic.co/t/geodistance-aggregation-is-not-working-with-nested-aggregation/26012/4 "2015-07-22T14:27:20Z")

</div>

No worries, it took me a little while to see it 😄

---

<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:** [July 5, 2017, 11:59pm UTC](https://discuss.elastic.co/t/geodistance-aggregation-is-not-working-with-nested-aggregation/26012/5 "2017-07-05T23:59:55Z")

</div>


