# Nested GeoDistance Query Doesn't Return Results

**URL:** <https://discuss.elastic.co/t/nested-geodistance-query-doesnt-return-results/151371>\
**Category:** Elasticsearch\
**Created:** [October 7, 2018, 8:15pm UTC](https://discuss.elastic.co/t/nested-geodistance-query-doesnt-return-results/151371 "2018-10-07T20:15:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![hacker\_21](https://avatars.discourse-cdn.com/v4/letter/h/a6a055/32.png) [@hacker\_21](https://discuss.elastic.co/u/hacker_21)\
**Post date:** [October 7, 2018, 8:15pm UTC](https://discuss.elastic.co/t/nested-geodistance-query-doesnt-return-results/151371/1 "2018-10-07T20:15:49Z")

</div>

I have the following mapping:  
mapping = """  
{  
"settings": {  
"analysis": {  
"analyzer" : "stop",  
"normalizer": {  
"lowercase\_normalizer": {  
"type": "custom",  
"char\_filter": [],  
"filter": ["lowercase"]  
}  
}  
}  
},  
"mappings": {  
"document": {  
"properties": {  
"postal\_codes" : {  
"type" : "nested",  
"properties" : {  
"location": {  
"type": "geo\_point"  
}  
}  
}  
}  
}  
}  
}  
"""

But when I run the correct query (I believe) it returns no results:  
GET /testing/\_search  
{  
"query": {  
"bool": {  
"must": {  
"match\_all" : {}  
},  
"filter": {  
"geo\_distance" : {  
"distance" : "1000km",  
"postal\_codes.location": {  
"lat" : 43.5034,  
"lon" : -79.8773  
}  
}  
}  
}  
}  
}

Even with a large distance and the exact coordinates I know exist in the index, it doesn't return any hits. I know the query works because when I ran a similar query without nested data, it returned the exact results it should have.

Any ideas what I'm doing wrong? Thanks,

---

<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:** [October 12, 2018, 10:05am UTC](https://discuss.elastic.co/t/nested-geodistance-query-doesnt-return-results/151371/2 "2018-10-12T10:05:31Z")

</div>

Nested objects needs to be queried with the nested query. You can rewrite your query as shown here:

```auto
GET testing/_search
{
  "query": {
    "nested": {
      "path": "postal_codes",
      "query": {
        "bool": {
          "must": {
            "match_all": {}
          },
          "filter": {
            "geo_distance": {
              "distance": "1000km",
              "postal_codes.location": {
                "lat": 43.5034,
                "lon": -79.8773
              }
            }
          }
        }
      }
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![hacker\_21](https://avatars.discourse-cdn.com/v4/letter/h/a6a055/32.png) [@hacker\_21](https://discuss.elastic.co/u/hacker_21)\
**Post date:** [October 14, 2018, 8:40pm UTC](https://discuss.elastic.co/t/nested-geodistance-query-doesnt-return-results/151371/3 "2018-10-14T20:40:06Z")

</div>

Thanks Ignacio!

---

<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:** [November 11, 2018, 8:40pm UTC](https://discuss.elastic.co/t/nested-geodistance-query-doesnt-return-results/151371/4 "2018-11-11T20:40:07Z")

</div>

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