# Geo location mapping and query

**URL:** <https://discuss.elastic.co/t/geo-location-mapping-and-query/7033>\
**Category:** Elasticsearch\
**Created:** [March 16, 2012, 10:55pm UTC](https://discuss.elastic.co/t/geo-location-mapping-and-query/7033 "2012-03-16T22:55:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dragan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dragan/32/2943_2.png) [@dragan](https://discuss.elastic.co/u/dragan)\
**Post date:** [March 16, 2012, 10:55pm UTC](https://discuss.elastic.co/t/geo-location-mapping-and-query/7033/1 "2012-03-16T22:55:27Z")

</div>

Hi,

I've created an index with the mapping below (I'm using pyes, but I  
reproduced the steps with curl) and I can't get the geo query to  
return any results. Please let me know what I'm doing wrong.

1. create index and mapping

curl -XPUT 'localhost:9200/locations\_index'

curl -XPUT '[http://localhost:9200/locations\_index/location/\_mapping](http://localhost:9200/locations_index/location/_mapping)' -d '  
{  
"location":{  
"properties":{  
"longId":{  
"type":"long",  
"store":"yes"  
},  
"id":{  
"include\_in\_all":"false",  
"index":"not\_analyzed",  
"type":"string",  
"store":"yes"  
},  
"pin":{  
"type":"geo\_point",  
"store":"yes"  
}  
}  
}  
}'

1. populate index

curl -XPUT '[http://localhost:9200/locations\_index/location/rd\_1700](http://localhost:9200/locations_index/location/rd_1700)' -d '  
{  
"longId": 1700,  
"id": "id\_1700",  
"pin": {  
"lat": 40.740000000000002,  
"lon": 73.989999999999995  
}  
}'

1. run a geo query

curl -XGET '[http://localhost:9200/locations\_index/location/\_search](http://localhost:9200/locations_index/location/_search)' -d '  
{  
"from": 0,  
"size": 10,  
"query": {  
"filtered": {  
"query": {  
"match\_all": {}  
},  
"filter": {  
"geo\_distance": {  
"distance": "10km",  
"pin": {  
"lat": 40.74,  
"lon": -73.99  
}  
}  
}  
}  
}  
}'

I can see the document I index via the head plugin, but I the query  
doesn't return it.

It returns:  
{  
"took":16,  
"timed\_out":false,  
"\_shards":{  
"total":5,  
"successful":5,  
"failed":0  
},  
"hits":{  
"total":0,  
"max\_score":null,  
"hits":[

```
  ]

```

}  
}

Thank you

---

<div class="post-metadata">

**Author:** ![egaumer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/egaumer/32/2365_2.png) [@egaumer](https://discuss.elastic.co/u/egaumer)\
**Post date:** [March 17, 2012, 11:59am UTC](https://discuss.elastic.co/t/geo-location-mapping-and-query/7033/2 "2012-03-17T11:59:42Z")

</div>

Look at the longitude you've indexed versus the one you are search for. Fix  
that error and this query should work fine.

On Friday, March 16, 2012 6:55:27 PM UTC-4, Dragan wrote:

> Hi,
> 
> I've created an index with the mapping below (I'm using pyes, but I  
> reproduced the steps with curl) and I can't get the geo query to  
> return any results. Please let me know what I'm doing wrong.
> 
> 1. create index and mapping
> 
> curl -XPUT 'localhost:9200/locations\_index'
> 
> curl -XPUT '[http://localhost:9200/locations\_index/location/\_mapping](http://localhost:9200/locations_index/location/_mapping)' -d '  
> {  
> "location":{  
> "properties":{  
> "longId":{  
> "type":"long",  
> "store":"yes"  
> },  
> "id":{  
> "include\_in\_all":"false",  
> "index":"not\_analyzed",  
> "type":"string",  
> "store":"yes"  
> },  
> "pin":{  
> "type":"geo\_point",  
> "store":"yes"  
> }  
> }  
> }  
> }'
> 
> 1. populate index
> 
> curl -XPUT '[http://localhost:9200/locations\_index/location/rd\_1700](http://localhost:9200/locations_index/location/rd_1700)' -d '  
> {  
> "longId": 1700,  
> "id": "id\_1700",  
> "pin": {  
> "lat": 40.740000000000002,  
> "lon": 73.989999999999995  
> }  
> }'
> 
> 1. run a geo query
> 
> curl -XGET '[http://localhost:9200/locations\_index/location/\_search](http://localhost:9200/locations_index/location/_search)' -d '  
> {  
> "from": 0,  
> "size": 10,  
> "query": {  
> "filtered": {  
> "query": {  
> "match\_all": {}  
> },  
> "filter": {  
> "geo\_distance": {  
> "distance": "10km",  
> "pin": {  
> "lat": 40.74,  
> "lon": -73.99  
> }  
> }  
> }  
> }  
> }  
> }'
> 
> I can see the document I index via the head plugin, but I the query  
> doesn't return it.
> 
> It returns:  
> {  
> "took":16,  
> "timed\_out":false,  
> "\_shards":{  
> "total":5,  
> "successful":5,  
> "failed":0  
> },  
> "hits":{  
> "total":0,  
> "max\_score":null,  
> "hits":[
> 
> ```
> ]
> 
> ```
> 
> }  
> }
> 
> Thank you

---

<div class="post-metadata">

**Author:** ![dragan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dragan/32/2943_2.png) [@dragan](https://discuss.elastic.co/u/dragan)\
**Post date:** [March 17, 2012, 4:45pm UTC](https://discuss.elastic.co/t/geo-location-mapping-and-query/7033/3 "2012-03-17T16:45:40Z")

</div>

Thank you Eric!

On Saturday, March 17, 2012 7:59:42 AM UTC-4, egaumer wrote:

> Look at the longitude you've indexed versus the one you are search for.  
> Fix that error and this query should work fine.
> 
> On Friday, March 16, 2012 6:55:27 PM UTC-4, Dragan wrote:
> 
> > Hi,
> > 
> > I've created an index with the mapping below (I'm using pyes, but I  
> > reproduced the steps with curl) and I can't get the geo query to  
> > return any results. Please let me know what I'm doing wrong.
> > 
> > 1. create index and mapping
> > 
> > curl -XPUT 'localhost:9200/locations\_index'
> > 
> > curl -XPUT '[http://localhost:9200/locations\_index/location/\_mapping](http://localhost:9200/locations_index/location/_mapping)' -d '  
> > {  
> > "location":{  
> > "properties":{  
> > "longId":{  
> > "type":"long",  
> > "store":"yes"  
> > },  
> > "id":{  
> > "include\_in\_all":"false",  
> > "index":"not\_analyzed",  
> > "type":"string",  
> > "store":"yes"  
> > },  
> > "pin":{  
> > "type":"geo\_point",  
> > "store":"yes"  
> > }  
> > }  
> > }  
> > }'
> > 
> > 1. populate index
> > 
> > curl -XPUT '[http://localhost:9200/locations\_index/location/rd\_1700](http://localhost:9200/locations_index/location/rd_1700)' -d '  
> > {  
> > "longId": 1700,  
> > "id": "id\_1700",  
> > "pin": {  
> > "lat": 40.740000000000002,  
> > "lon": 73.989999999999995  
> > }  
> > }'
> > 
> > 1. run a geo query
> > 
> > curl -XGET '[http://localhost:9200/locations\_index/location/\_search](http://localhost:9200/locations_index/location/_search)' -d '  
> > {  
> > "from": 0,  
> > "size": 10,  
> > "query": {  
> > "filtered": {  
> > "query": {  
> > "match\_all": {}  
> > },  
> > "filter": {  
> > "geo\_distance": {  
> > "distance": "10km",  
> > "pin": {  
> > "lat": 40.74,  
> > "lon": -73.99  
> > }  
> > }  
> > }  
> > }  
> > }  
> > }'
> > 
> > I can see the document I index via the head plugin, but I the query  
> > doesn't return it.
> > 
> > It returns:  
> > {  
> > "took":16,  
> > "timed\_out":false,  
> > "\_shards":{  
> > "total":5,  
> > "successful":5,  
> > "failed":0  
> > },  
> > "hits":{  
> > "total":0,  
> > "max\_score":null,  
> > "hits":[
> > 
> > ```
> > ]
> > 
> > ```
> > 
> > }  
> > }
> > 
> > Thank you

---

<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:** [July 6, 2017, 3:35am UTC](https://discuss.elastic.co/t/geo-location-mapping-and-query/7033/4 "2017-07-06T03:35:44Z")

</div>


