# Geo\_Bounding\_Box Returning Bogus Results

**URL:** <https://discuss.elastic.co/t/geo-bounding-box-returning-bogus-results/13687>\
**Category:** Elasticsearch\
**Created:** [September 19, 2013, 1:26pm UTC](https://discuss.elastic.co/t/geo-bounding-box-returning-bogus-results/13687 "2013-09-19T13:26:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shawn\_Evans](https://avatars.discourse-cdn.com/v4/letter/s/3e96dc/32.png) [@Shawn\_Evans](https://discuss.elastic.co/u/Shawn_Evans)\
**Post date:** [September 19, 2013, 1:26pm UTC](https://discuss.elastic.co/t/geo-bounding-box-returning-bogus-results/13687/1 "2013-09-19T13:26:37Z")

</div>

I'm quite new to ElasticSearch, and I'm having some problems getting  
accurate results out of the geo\_bounding\_box filter. It's my understanding  
that given 2 points, the geo\_bounding\_box will return all results that fall  
within the designated area defined by the points. I'm using Python with  
the json library to get data into a proper \_bulk index format, and a  
'\_bulk' request to insert the data into ES. Here's the gist of it:

1. Create the index:

$ curl -XPUT '[http://localhost:9200/geodata/](http://localhost:9200/geodata/)'  
{"ok":true,"acknowledged":true}

1. Create a mapping:

$ curl -XPUT '[http://localhost:9200/geodata/record/\_mapping](http://localhost:9200/geodata/record/_mapping)' -d '{  
"record": { "properties" : { "city" : {"type" : "string"}, "region\_code" :  
{"type":"string"},g"}, "country\_code" : {"type":"string"},  
"country\_name":{"type":"string"}, "email":{"type":"string"}, "Location" : {  
"type" : "geo\_point" }, "area\_code" : {"type":"string"} } } }'  
{"ok":true,"acknowledged":true}

1. Insert data in the following format (roughly 350k records):

{"index": {"\_type": "record", "\_id": 80, "\_index": "geodata"}}  
{"city": "Tokyo", "region\_code": "40", "postal\_code": null, "Location":  
[139.7514, 35.685], "country\_code": "JPN", "country\_name": "Japan",  
"email": "testing1@example.com", "area\_code": 0}

After indexing the data, I verified that everything worked properly:

$ curl '[http://localhost:9200/geodata/record/237718/](http://localhost:9200/geodata/record/237718/)'  
{"\_index":"geodata","\_type":"record","\_id":"237718","\_version":1,"exists":true,  
"\_source" : {"city": "Reading", "region\_code": "PA", "postal\_code":  
"19607", "Location": [-75.9523, 40.2851], "country\_code": "USA",  
"country\_name": "United States", "email": "testing2@example.com",  
"area\_code": 610}}

1. With the data indexed I attempted to run a query with a  
geo\_bounding\_box filter.

$ curl  
'[http://localhost:9200/geodata/record/\_search?pretty=true&size=1000000](http://localhost:9200/geodata/record/_search?pretty=true&size=1000000)' -d  
'{ "query" : { "filtered" : { "query" : { "match\_all":{}},"filter": {  
"geo\_bounding\_box": {"Lcation" : { "top\_left" :[-75.961189,40.371659]  
,"bottom\_right ": [-75.892525,40.297858] } } } } } } } }'

1. The request above returns results, but the results that are returned  
are not even close to the small bounding area I have defined in the query.  
The query above should return results for a small town in Pennsylvania,  
however the results included hits from Portugal and Spain, which are well  
outside of my bounding box. I've tried changing the Location (geo\_point  
value) to every format defined in the geo\_point reference guide  
([http://www.elasticsearch.org/guide/reference/mapping/geo-point-type/](http://www.elasticsearch.org/guide/reference/mapping/geo-point-type/)) to  
no avail. I've tried using a nested Location in the format of  
"Pin.location". I've tried forgoing a mapping and going with the 'dynamic'  
type, but everything seems to return the same incorrect results. Any  
assistance or advice would be hugely appreciated. Thanks!

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Shawn\_Evans](https://avatars.discourse-cdn.com/v4/letter/s/3e96dc/32.png) [@Shawn\_Evans](https://discuss.elastic.co/u/Shawn_Evans)\
**Post date:** [September 19, 2013, 2:01pm UTC](https://discuss.elastic.co/t/geo-bounding-box-returning-bogus-results/13687/2 "2013-09-19T14:01:07Z")

</div>

So here' s a follow up:

it turns out that my query was returning bad results because I had a typo  
in my filter:

"bottom\_right " vs "bottom\_right"

They key difference being the additional space in the first one. So with  
that issue identified, I'm now not getting ANY results back:

$ curl  
'[http://localhost:9200/geodata/record/\_search?pretty=true&size=1000000](http://localhost:9200/geodata/record/_search?pretty=true&size=1000000)' -d  
'{ "query" : { "filtered" : { "query" : { "match\_all":{}},"filter": {  
"geo\_bounding\_box": {"Lcation" : { "top\_left" : [-75.961189, 40.371659]  
,"bottom\_right" : [-75.892525, 40.297858] } } } } } } } }'  
{  
"took" : 3,  
"timed\_out" : false,  
"\_shards" : {  
"total" : 5,  
"successful" : 5,  
"failed" : 0  
},  
"hits" : {  
"total" : 0,  
"max\_score" : null,  
"hits" :   
}

Still zero clues as to why. I'm positive I'm doing something wrong, but  
lack the experience to know what exactly. Thanks!

On Thursday, September 19, 2013 9:26:37 AM UTC-4, Shawn Evans wrote:

> I'm quite new to Elasticsearch, and I'm having some problems getting  
> accurate results out of the geo\_bounding\_box filter. It's my understanding  
> that given 2 points, the geo\_bounding\_box will return all results that fall  
> within the designated area defined by the points. I'm using Python with  
> the json library to get data into a proper \_bulk index format, and a  
> '\_bulk' request to insert the data into ES. Here's the gist of it:
> 
> 1. Create the index:
> 
> $ curl -XPUT '[http://localhost:9200/geodata/](http://localhost:9200/geodata/)'  
> {"ok":true,"acknowledged":true}
> 
> 1. Create a mapping:
> 
> $ curl -XPUT '[http://localhost:9200/geodata/record/\_mapping](http://localhost:9200/geodata/record/_mapping)' -d '{  
> "record": { "properties" : { "city" : {"type" : "string"}, "region\_code" :  
> {"type":"string"},g"}, "country\_code" : {"type":"string"},  
> "country\_name":{"type":"string"}, "email":{"type":"string"}, "Location" : {  
> "type" : "geo\_point" }, "area\_code" : {"type":"string"} } } }'  
> {"ok":true,"acknowledged":true}
> 
> 1. Insert data in the following format (roughly 350k records):
> 
> {"index": {"\_type": "record", "\_id": 80, "\_index": "geodata"}}  
> {"city": "Tokyo", "region\_code": "40", "postal\_code": null, "Location":  
> [139.7514, 35.685], "country\_code": "JPN", "country\_name": "Japan",  
> "email": "[testing1@example.com](mailto:testing1@example.com)", "area\_code": 0}
> 
> After indexing the data, I verified that everything worked properly:
> 
> $ curl '[http://localhost:9200/geodata/record/237718/](http://localhost:9200/geodata/record/237718/)'  
> {"\_index":"geodata","\_type":"record","\_id":"237718","\_version":1,"exists":true,  
> "\_source" : {"city": "Reading", "region\_code": "PA", "postal\_code":  
> "19607", "Location": [-75.9523, 40.2851], "country\_code": "USA",  
> "country\_name": "United States", "email": "[testing2@example.com](mailto:testing2@example.com)",  
> "area\_code": 610}}
> 
> 1. With the data indexed I attempted to run a query with a  
> geo\_bounding\_box filter.
> 
> $ curl '  
> [http://localhost:9200/geodata/record/\_search?pretty=true&size=1000000](http://localhost:9200/geodata/record/_search?pretty=true&size=1000000)' -d  
> '{ "query" : { "filtered" : { "query" : { "match\_all":{}},"filter": {  
> "geo\_bounding\_box": {"Lcation" : { "top\_left" :[-75.961189,40.371659]  
> ,"bottom\_right ": [-75.892525,40.297858] } } } } } } } }'
> 
> 1. The request above returns results, but the results that are returned  
> are not even close to the small bounding area I have defined in the query.  
> The query above should return results for a small town in Pennsylvania,  
> however the results included hits from Portugal and Spain, which are well  
> outside of my bounding box. I've tried changing the Location (geo\_point  
> value) to every format defined in the geo\_point reference guide (  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/geo-point-type/)) to  
> no avail. I've tried using a nested Location in the format of  
> "Pin.location". I've tried forgoing a mapping and going with the 'dynamic'  
> type, but everything seems to return the same incorrect results. Any  
> assistance or advice would be hugely appreciated. Thanks!

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Shawn\_Evans](https://avatars.discourse-cdn.com/v4/letter/s/3e96dc/32.png) [@Shawn\_Evans](https://discuss.elastic.co/u/Shawn_Evans)\
**Post date:** [September 19, 2013, 2:11pm UTC](https://discuss.elastic.co/t/geo-bounding-box-returning-bogus-results/13687/3 "2013-09-19T14:11:48Z")

</div>

So, I realize that my "Location" field is also a typo, but that's an  
artifact of strange copy/paste behavior due to unprintable characters on  
the command line doing funky things to subsequent input (and apparently  
copy/paste). Anyways, the actual query:

$ curl  
'[http://localhost:9200/geodude/record/\_search?pretty=true&size=1000000](http://localhost:9200/geodude/record/_search?pretty=true&size=1000000)' -d  
'{ "query" : { "filtered" : { "query" : { "match\_all":{}},"filter": {  
"geo\_bounding\_box": {"Location" : { "top\_left" : [-75.961189, 40.371659]  
,"bottom\_right" : [-75.892525, 40.297858] } } } } } } } }'

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

Sorry about the multi post.

On Thursday, September 19, 2013 10:01:07 AM UTC-4, Shawn Evans wrote:

> So here' s a follow up:
> 
> it turns out that my query was returning bad results because I had a typo  
> in my filter:
> 
> "bottom\_right " vs "bottom\_right"
> 
> They key difference being the additional space in the first one. So with  
> that issue identified, I'm now not getting ANY results back:
> 
> $ curl '  
> [http://localhost:9200/geodata/record/\_search?pretty=true&size=1000000](http://localhost:9200/geodata/record/_search?pretty=true&size=1000000)' -d  
> '{ "query" : { "filtered" : { "query" : { "match\_all":{}},"filter": {  
> "geo\_bounding\_box": {"Lcation" : { "top\_left" : [-75.961189, 40.371659]  
> ,"bottom\_right" : [-75.892525, 40.297858] } } } } } } } }'  
> {  
> "took" : 3,  
> "timed\_out" : false,  
> "\_shards" : {  
> "total" : 5,  
> "successful" : 5,  
> "failed" : 0  
> },  
> "hits" : {  
> "total" : 0,  
> "max\_score" : null,  
> "hits" :   
> }
> 
> Still zero clues as to why. I'm positive I'm doing something wrong, but  
> lack the experience to know what exactly. Thanks!
> 
> On Thursday, September 19, 2013 9:26:37 AM UTC-4, Shawn Evans wrote:
> 
> > I'm quite new to Elasticsearch, and I'm having some problems getting  
> > accurate results out of the geo\_bounding\_box filter. It's my understanding  
> > that given 2 points, the geo\_bounding\_box will return all results that fall  
> > within the designated area defined by the points. I'm using Python with  
> > the json library to get data into a proper \_bulk index format, and a  
> > '\_bulk' request to insert the data into ES. Here's the gist of it:
> > 
> > 1. Create the index:
> > 
> > $ curl -XPUT '[http://localhost:9200/geodata/](http://localhost:9200/geodata/)'  
> > {"ok":true,"acknowledged":true}
> > 
> > 1. Create a mapping:
> > 
> > $ curl -XPUT '[http://localhost:9200/geodata/record/\_mapping](http://localhost:9200/geodata/record/_mapping)' -d '{  
> > "record": { "properties" : { "city" : {"type" : "string"}, "region\_code" :  
> > {"type":"string"},g"}, "country\_code" : {"type":"string"},  
> > "country\_name":{"type":"string"}, "email":{"type":"string"}, "Location" : {  
> > "type" : "geo\_point" }, "area\_code" : {"type":"string"} } } }'  
> > {"ok":true,"acknowledged":true}
> > 
> > 1. Insert data in the following format (roughly 350k records):
> > 
> > {"index": {"\_type": "record", "\_id": 80, "\_index": "geodata"}}  
> > {"city": "Tokyo", "region\_code": "40", "postal\_code": null, "Location":  
> > [139.7514, 35.685], "country\_code": "JPN", "country\_name": "Japan",  
> > "email": "[testing1@example.com](mailto:testing1@example.com)", "area\_code": 0}
> > 
> > After indexing the data, I verified that everything worked properly:
> > 
> > $ curl '[http://localhost:9200/geodata/record/237718/](http://localhost:9200/geodata/record/237718/)'  
> > {"\_index":"geodata","\_type":"record","\_id":"237718","\_version":1,"exists":true,  
> > "\_source" : {"city": "Reading", "region\_code": "PA", "postal\_code":  
> > "19607", "Location": [-75.9523, 40.2851], "country\_code": "USA",  
> > "country\_name": "United States", "email": "[testing2@example.com](mailto:testing2@example.com)",  
> > "area\_code": 610}}
> > 
> > 1. With the data indexed I attempted to run a query with a  
> > geo\_bounding\_box filter.
> > 
> > $ curl '  
> > [http://localhost:9200/geodata/record/\_search?pretty=true&size=1000000](http://localhost:9200/geodata/record/_search?pretty=true&size=1000000)'  
> > -d '{ "query" : { "filtered" : { "query" : { "match\_all":{}},"filter": {  
> > "geo\_bounding\_box": {"Lcation" : { "top\_left" :[-75.961189,40.371659]  
> > ,"bottom\_right ": [-75.892525,40.297858] } } } } } } } }'
> > 
> > 1. The request above returns results, but the results that are returned  
> > are not even close to the small bounding area I have defined in the query.  
> > The query above should return results for a small town in Pennsylvania,  
> > however the results included hits from Portugal and Spain, which are well  
> > outside of my bounding box. I've tried changing the Location (geo\_point  
> > value) to every format defined in the geo\_point reference guide (  
> > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/geo-point-type/)) to  
> > no avail. I've tried using a nested Location in the format of  
> > "Pin.location". I've tried forgoing a mapping and going with the 'dynamic'  
> > type, but everything seems to return the same incorrect results. Any  
> > assistance or advice would be hugely appreciated. Thanks!

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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, 2:15am UTC](https://discuss.elastic.co/t/geo-bounding-box-returning-bogus-results/13687/4 "2017-07-06T02:15:32Z")

</div>


