# Geo\_distance query always returns results, regardless of distance, latitude, or longitude

**URL:** <https://discuss.elastic.co/t/geo-distance-query-always-returns-results-regardless-of-distance-latitude-or-longitude/169968>\
**Category:** Elasticsearch\
**Created:** [February 26, 2019, 9:46am UTC](https://discuss.elastic.co/t/geo-distance-query-always-returns-results-regardless-of-distance-latitude-or-longitude/169968 "2019-02-26T09:46:14Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![rythem](https://avatars.discourse-cdn.com/v4/letter/r/3ec8ea/32.png) [@rythem](https://discuss.elastic.co/u/rythem)\
**Post date:** [February 26, 2019, 9:46am UTC](https://discuss.elastic.co/t/geo-distance-query-always-returns-results-regardless-of-distance-latitude-or-longitude/169968/1 "2019-02-26T09:46:14Z")

</div>

I've been trying out the geo\_distance query on the latest version of Elasticsearch (6.6), but it seems I always get hits/results back. If I follow the example here and change either the latitude/longitude to something way off with a distance of 1 km, I'm still getting hits back.

[https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-geo-distance-query.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-geo-distance-query.html)

For example, the following query is still returning a result:

```
GET http://localhost:9200/my_locations/_search
{
    "query": {
        "bool" : {
            "must" : {
                "match_all" : {}
            },
            "filter" : {
                "geo_distance" : {
                    "distance" : "1km",
                    "pin.location" : [30, 0]
                }
            }
        }
    }
}

```

Is there something obvious I'm missing here??? I've attached the full Elasticsearch build information below

```
{
  "name" : "PrZXr5l",
  "cluster_name" : "elasticsearch_luke",
  "cluster_uuid" : "VJKApkuYTx6KIfIx3O23Ig",
  "version" : {
    "number" : "6.6.1",
    "build_flavor" : "oss",
    "build_type" : "tar",
    "build_hash" : "1fd8f69",
    "build_date" : "2019-02-13T17:10:04.160291Z",
    "build_snapshot" : false,
    "lucene_version" : "7.6.0",
    "minimum_wire_compatibility_version" : "5.6.0",
    "minimum_index_compatibility_version" : "5.0.0"
  },
  "tagline" : "You Know, for Search"
}
```

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [February 26, 2019, 10:23am UTC](https://discuss.elastic.co/t/geo-distance-query-always-returns-results-regardless-of-distance-latitude-or-longitude/169968/2 "2019-02-26T10:23:46Z")

</div>

What is a typical result you are getting you should not get back?

Could you provide a full recreation script as described in [About the Elasticsearch category](https://discuss.elastic.co/t/about-the-elasticsearch-category/21). It will help to better understand what you are doing. Please, try to keep the example as simple as possible.

A full reproduction script will help readers to understand, reproduce and if needed fix your problem. It will also most likely help to get a faster answer.

---

<div class="post-metadata">

**Author:** ![rythem](https://avatars.discourse-cdn.com/v4/letter/r/3ec8ea/32.png) [@rythem](https://discuss.elastic.co/u/rythem)\
**Post date:** [February 26, 2019, 10:41am UTC](https://discuss.elastic.co/t/geo-distance-query-always-returns-results-regardless-of-distance-latitude-or-longitude/169968/3 "2019-02-26T10:41:48Z")

</div>

David,

Thanks for the fast response! The reproduction script is in your documentation in the link in my previous post... I can copy/paste it here if you'd like though for completeness later on?

I expect to not get any results back if I'm specifying a distance with a latitude/longitude outside of the given data set. As I mentioned in my previous post, if I'm at a longitude/latitude of 30/0 with a 1 kilometer distance, I definitely shouldn't be returning a point back with a latitude of 40.12 and longitude -71.34... that's significantly further away than 1 km...

---

<div class="post-metadata">

**Author:** ![rythem](https://avatars.discourse-cdn.com/v4/letter/r/3ec8ea/32.png) [@rythem](https://discuss.elastic.co/u/rythem)\
**Post date:** [February 26, 2019, 10:43am UTC](https://discuss.elastic.co/t/geo-distance-query-always-returns-results-regardless-of-distance-latitude-or-longitude/169968/4 "2019-02-26T10:43:13Z")

</div>

Copy/pasting Elastic's documentation here for future reference/readers

```
PUT /my_locations
{
    "mappings": {
        "_doc": {
            "properties": {
                "pin": {
                    "properties": {
                        "location": {
                            "type": "geo_point"
                        }
                    }
                }
            }
        }
    }
}

PUT /my_locations/_doc/1
{
    "pin" : {
        "location" : {
            "lat" : 40.12,
            "lon" : -71.34
        }
    }
}

GET /my_locations/_search
{
    "query": {
        "bool" : {
            "must" : {
                "match_all" : {}
            },
            "filter" : {
                "geo_distance" : {
                    "distance" : "1km",
                    "pin.location" : [30, 0]
                }
            }
        }
    }
}

```

This is returning a hit when the data point being returned is definitely not within 1 kilometer of longitude 30, latitude 0

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [February 26, 2019, 5:11pm UTC](https://discuss.elastic.co/t/geo-distance-query-always-returns-results-regardless-of-distance-latitude-or-longitude/169968/5 "2019-02-26T17:11:37Z")

</div>

I just tried this script (in 7.0.0-beta1 though but I'm going to try in 6.6):

```auto
DELETE /my_locations
PUT /my_locations
{
  "mappings": {
    "properties": {
      "pin": {
        "properties": {
          "location": {
            "type": "geo_point"
          }
        }
      }
    }
  }
}

PUT /my_locations/_doc/1
{
    "pin" : {
        "location" : {
            "lat" : 40.12,
            "lon" : -71.34
        }
    }
}

GET /my_locations/_search
{
    "query": {
        "bool" : {
            "must" : {
                "match_all" : {}
            },
            "filter" : {
                "geo_distance" : {
                    "distance" : "1km",
                    "pin.location" : [30, 0]
                }
            }
        }
    }
}

```

And this gives:

```auto
{
  "took" : 104,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 0,
      "relation" : "eq"
    },
    "max_score" : null,
    "hits" : []
  }
}

```

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [February 26, 2019, 5:14pm UTC](https://discuss.elastic.co/t/geo-distance-query-always-returns-results-regardless-of-distance-latitude-or-longitude/169968/6 "2019-02-26T17:14:40Z")

</div>

Same in 6.6.1. No hits returned.

Are you sure that:

- You are running exactly this script?
- You are using the latest 6.6.1 version?

---

<div class="post-metadata">

**Author:** ![rythem](https://avatars.discourse-cdn.com/v4/letter/r/3ec8ea/32.png) [@rythem](https://discuss.elastic.co/u/rythem)\
**Post date:** [February 27, 2019, 1:53pm UTC](https://discuss.elastic.co/t/geo-distance-query-always-returns-results-regardless-of-distance-latitude-or-longitude/169968/7 "2019-02-27T13:53:43Z")

</div>

David,

Thank you for the super fast responses! If I try your following script below, I get an error:

```
PUT /my_locations
{
  "mappings": {
    "properties": {
      "pin": {
        "properties": {
          "location": {
            "type": "geo_point"
          }
        }
      }
    }
  }
}

```

I noticed yours doesn't have a "\_doc" key in the payload for the mappings.. is this a caveat of 7.0.0-beta1 for you? If I try this on 6.6.1 it returns a 400 with the error message:

```
{
  "error": {
    "root_cause": [
      {
        "type": "mapper_parsing_exception",
        "reason": "Root mapping definition has unsupported parameters: [pin : {properties={location={type=geo_point}}}]"
      }
    ],
    "type": "mapper_parsing_exception",
    "reason": "Failed to parse mapping [properties]: Root mapping definition has unsupported parameters: [pin : {properties={location={type=geo_point}}}]",
    "caused_by": {
      "type": "mapper_parsing_exception",
      "reason": "Root mapping definition has unsupported parameters: [pin : {properties={location={type=geo_point}}}]"
    }
  },
  "status": 400
}

```

Is there something else off here? I've included the build version higher in this thread. Is there a known issue with that release version?

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [February 27, 2019, 2:10pm UTC](https://discuss.elastic.co/t/geo-distance-query-always-returns-results-regardless-of-distance-latitude-or-longitude/169968/8 "2019-02-27T14:10:50Z")

</div>

Yeah. It's because I'm using 7.0 and not 6.x.

You can add `_doc` in the mapping between `mappings` and `properties` and that will work on 6.x

---

<div class="post-metadata">

**Author:** ![rythem](https://avatars.discourse-cdn.com/v4/letter/r/3ec8ea/32.png) [@rythem](https://discuss.elastic.co/u/rythem)\
**Post date:** [February 27, 2019, 2:33pm UTC](https://discuss.elastic.co/t/geo-distance-query-always-returns-results-regardless-of-distance-latitude-or-longitude/169968/9 "2019-02-27T14:33:19Z")

</div>

Okay, then that's verbatim the script I have above and I'm still getting back a response:

**Request**  
GET [http://localhost:9200/my\_locations/\_search](http://localhost:9200/my_locations/_search)

```
{
    "query": {
        "bool" : {
            "must" : {
                "match_all" : {}
            },
            "filter" : {
                "geo_distance" : {
                    "distance" : "1km",
                    "pin.location" : [30, 0]
                }
            }
        }
    }
}

```

**Response**

```
{
    "took": 79,
    "timed_out": false,
    "_shards": {
    "total": 5,
    "successful": 5,
    "skipped": 0,
    "failed": 0
    },
    "hits": {
        "total": 1,
        "max_score": 1,
        "hits": [
            {
            "_index": "my_locations",
            "_type": "_doc",
            "_id": "1",
            "_score": 1,
            "_source": {
                "pin": {
                    "location": {
                        "lat": 40.12,
                        "lon": -71.34
                    }
                }
            }
            }
        ]
    }
}

```

Are there any additional tweaks/plugins/things I have to have installed in my Elasticsearch instance? I'm trying to figure out what we're doing differently here.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [February 27, 2019, 2:47pm UTC](https://discuss.elastic.co/t/geo-distance-query-always-returns-results-regardless-of-distance-latitude-or-longitude/169968/10 "2019-02-27T14:47:10Z")

</div>

I suspect that you put a blank line in Kibana console between:

```auto
GET http://localhost:9200/my_locations/_search

```

and

```auto
{
    "query": {
        "bool" : {
            "must" : {
                "match_all" : {}
            },
            "filter" : {
                "geo_distance" : {
                    "distance" : "1km",
                    "pin.location" : [30, 0]
                }
            }
        }
    }
}

```

Did you?

Or that you are not running this exact script in Kibana dev console.

---

<div class="post-metadata">

**Author:** ![rythem](https://avatars.discourse-cdn.com/v4/letter/r/3ec8ea/32.png) [@rythem](https://discuss.elastic.co/u/rythem)\
**Post date:** [February 27, 2019, 2:57pm UTC](https://discuss.elastic.co/t/geo-distance-query-always-returns-results-regardless-of-distance-latitude-or-longitude/169968/11 "2019-02-27T14:57:02Z")

</div>

Figured it out! This is an issue with the REST client I'm using (Paw from [https://paw.cloud](https://paw.cloud)). Apparently, it's stripping out the body on GET requests. When I tried the above with Postman, it sent the payload and got the response correctly. Thanks for the help @dadoonet!!

For other people that hit this problem with Paw, here's how you enable the payload on any request:

> **[Always Send Request Body (Paw Documentation)](https://paw.cloud/docs/advanced/always-send-request-body)**
>
> Always Send Request Body (Documentation of Paw, the most advanced HTTP client for Mac)

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [February 27, 2019, 3:34pm UTC](https://discuss.elastic.co/t/geo-distance-query-always-returns-results-regardless-of-distance-latitude-or-longitude/169968/12 "2019-02-27T15:34:59Z")

</div>

You should have tell me from the start.  
Actually Kibana transforms GET with body to POST requests as many browsers if not all do not support GET with a body.

---

<div class="post-metadata">

**Author:** ![rythem](https://avatars.discourse-cdn.com/v4/letter/r/3ec8ea/32.png) [@rythem](https://discuss.elastic.co/u/rythem)\
**Post date:** [February 27, 2019, 3:44pm UTC](https://discuss.elastic.co/t/geo-distance-query-always-returns-results-regardless-of-distance-latitude-or-longitude/169968/13 "2019-02-27T15:44:39Z")

</div>

Good to know. Thank you @dadoonet

---

<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:** [March 27, 2019, 3:47pm UTC](https://discuss.elastic.co/t/geo-distance-query-always-returns-results-regardless-of-distance-latitude-or-longitude/169968/14 "2019-03-27T15:47:49Z")

</div>

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