Nested GeoDistance Query Doesn't Return Results

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,

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

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
              }
            }
          }
        }
      }
    }
  }
}

Thanks Ignacio!

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