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.
- Create index
POST: http://localhost:9200/retail
{
"settings": {
"number_of_shards": 1,
"number_of_replicas": 0
},
"mappings": {
"restaurant": {
"properties": {
"location": {"type": "geo_point"}
}
}
}
}
- 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.