Geo_distance not working

I am trying to write geo_distance query, but not getting correct result.
I am using Elasticsearch 2.3.3
I have two documents one is located in Los Angeles and other one is in New York.
I am trying to get document near Los Angeles. But as a result I am getting two documents.
Below here is all my requests.

  1. Create index

POST: http://localhost:9200/retail
{
"settings": {
"number_of_shards": 1,
"number_of_replicas": 0
},
"mappings": {
"restaurant": {
"properties": {
"location": {"type": "geo_point"}
}
}
}
}

  1. Indexed documents
    PUT: http://localhost:9200/retail/restaurant/1
    {
    "name": "Restaurant1",
    "description": "Nice restaurant",
    "address": {
    "street": "464 Main St",
    "City": "Los Angeles",
    "State": "CA",
    "zip": "90013"
    },
    "location": {
    "lat": 34.0466,
    "lon": -118.248144
    }
    "tags": [
    "italian",
    "spaghetti",
    "pasta"
    ],
    "rating": "4.5"
    }

PUT: http://localhost:9200/retail/restaurant/2

{
"name": "Restaurant2",
"description": "Good restaurant",
"address": {
"street": "230 W 4th St",
"City": "New York",
"State": "NY",
"zip": "10014"
},
"location": {
"lat": 40.7543385,
"lon": -73.976313
},
"tags": [
"maxican",
"tacons",
"burritos"
],
"rating": "4.3"
}

Query string : as per https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-geo-distance-query.html

GET: http://localhost:9200/retail/restaurant/_search
{
"bool" : {
"must" : {
"match_all" : {}
},
"filter" : {
"geo_distance" : {
"distance" : "2km",
"location" : {
"lat": 34.0466,
"lon": -118.248144
}
}
}
}
}

Total result found 2 but expected 1.

Are you sure your index only contains the two documents you've listed and you don't have some older test data in there?

This is my test index. I created it only for this post. Just to make sure geo distance works fine so that I can use the same for my production index which has 1 million data.
Yes I do not have any other document under this index.
And I did check the output. Output has two sources which are same as documents I indexed under this index.
I am looking for your kind help.
Thanks

Finally I am able to get proper result.
I used below query. With POST request. Previously I was using GET.
{
"query": {
"filtered": {
"query": {
"match_all": {}
},
"filter": {
"geo_distance": {
"distance": "10000km",
"location": {
"lat": 40.7543385,
"lon": -73.976313
}
}
}
}
}
}

Thanks Joshua for your response. I appreciate your time.

Some clients don't support GET with body.
IIRC Sense rewrite GET with body requests to POST requests.

Good catch @sabiriqbal. As @dadoonet mentions, you can use GET or POST for this request, but some clients don't support a GET request with a body. If unsure, use POST :slight_smile:

Thanks @dadoonet and @Joshua_Rich for your kind help. Yes I got it. I was using Elasticsearch "head" plugin to execute test query. As David said "some client doesn't support GET with body", I think "head" plugin is one of those kind of client.