# (My) Problem with geo\_bounding\_box

**URL:** https://discuss.elastic.co/t/my-problem-with-geo-bounding-box/11825
**Category:** Elasticsearch
**Created:** [May 6, 2013, 5:03am UTC](https://discuss.elastic.co/t/my-problem-with-geo-bounding-box/11825 "2013-05-06T05:03:04Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Steve\_Baldwin](https://avatars.discourse-cdn.com/v4/letter/s/fbc32d/32.png) [@Steve\_Baldwin](https://discuss.elastic.co/u/Steve_Baldwin)
#### Post date: [May 6, 2013, 5:03am UTC](https://discuss.elastic.co/t/my-problem-with-geo-bounding-box/11825/1 "2013-05-06T05:03:04Z")

</div>

Hi,

I'm a new es user but love what I've seen so far. I'm using 0.90.0.

I have a simple mapping defined like this:

{  
"mappings" : {  
"user" : {  
"properties" : {  
"user\_name" : {  
"type" : "string",  
"index\_options" : "freqs",  
"boost" : 3.0  
},  
"handle" : {  
"type" : "string",  
"index\_options" : "docs"  
},  
"bio" : {  
"type" : "string",  
"index\_options" : "freqs"  
},  
"location" : {  
"type" : "geo\_point",  
"lat\_lon" : true  
}  
}  
},  
"post" : {  
"properties" : {  
"text" : {  
"type" : "string",  
"index\_options" : "freqs"  
},  
"location" : {  
"type" : "geo\_point",  
"lat\_lon" : true  
}  
}  
}  
}  
}

I've loaded around 50k entries into the index.

I want to be able to perform searches based on text and optionally filtered  
by a geo\_bounding\_box.

If I issue the following search, it works beautifully:

curl -XGET localhost:9200/wotzere/\_search?pretty=1 -d '  
{  
"fields" : ["\_id", "\_type", "location"],  
"from" : 0,  
"size" : 20,  
"query" : {  
"match": {  
"\_all" : "chill ice lodge"  
}  
}  
}'

It returns:

{  
"took" : 5,  
"timed\_out" : false,  
"\_shards" : {  
"total" : 5,  
"successful" : 5,  
"failed" : 0  
},  
"hits" : {  
"total" : 1170,  
"max\_score" : 2.2864966,  
"hits" : [ {  
"\_index" : "wotzere",  
"\_type" : "user",  
"\_id" : "80248",  
"\_score" : 2.2864966,  
"fields" : {  
"location" : ["145.0450", "-37.8232"]  
}  
}, {  
"\_index" : "wotzere",  
"\_type" : "user",  
"\_id" : "66694",  
"\_score" : 1.3186983,  
"fields" : {  
"location" : ["144.9679", "-37.8205"]  
}  
}, {  
"\_index" : "wotzere",  
"\_type" : "user",  
"\_id" : "72829",  
"\_score" : 0.76025414,  
"fields" : {  
"location" : ["151.3003", "-32.7730"]  
}  
}, {  
"\_index" : "wotzere",  
"\_type" : "user",  
"\_id" : "70022",  
"\_score" : 0.6828435,  
"fields" : {  
"location" : ["150.2991", "-34.6497"]  
}  
}, {  
"\_index" : "wotzere",  
"\_type" : "post",  
"\_id" : "138114",  
"\_score" : 0.52798617,  
"fields" : {  
"location" : ["130.8392", "-12.4630"]  
}  
}, {  
:  
} ]  
}  
}

For the life of me I can't get a geo\_bounding\_box filter to work - even on  
its own. Would some kind soul please point me in the right direction by  
incorporating a bounding box of (lat, long) tl =\> (-10, 110), br =\> (-44,  
155) into my original search criteria?

One thing that's not clear to me. If I have a field called "location" in  
both my types (user, post), do I need to specify both in separate  
geo\_bounding\_box filters or can I do it with a single, unqualified filter  
(sort of like what I'm doing with the "\_all" of the original criteria)?

Thanks so much.

Steve

--  
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: ![chilling](https://avatars.discourse-cdn.com/v4/letter/c/b3f665/32.png) [@chilling](https://discuss.elastic.co/u/chilling)
#### Post date: [May 6, 2013, 11:42am UTC](https://discuss.elastic.co/t/my-problem-with-geo-bounding-box/11825/2 "2013-05-06T11:42:05Z")

</div>

Hi Steve,

you can setup your geo\_bounding\_box filter by just adding a  
geo\_bounding\_box filter:

curl -XGET '[http://127.0.0.1:9200/posts/\_search?pretty=true](http://127.0.0.1:9200/posts/_search?pretty=true)' -d '{

```
    "fields" : ["_id", "_type", "location"],
    "from" : 0,
    "size" : 20,
    "query" : {
        "match": {
            "_all" : "chilling"
        }
    },

    "filter" : {
        "geo_bounding_box" : {
            "location" : {
                "top_left" : {
                    "lat" : -10.0,
                    "lon" : 110.0
                },
                "bottom_right" : {
                    "lat" : -44.0,
                    "lon" : 155
                }
            }
        }
    }

```

}'

I hope, this will help you,  
Florian

On Monday, May 6, 2013 7:03:04 AM UTC+2, Steve Baldwin wrote:

> Hi,
> 
> I'm a new es user but love what I've seen so far. I'm using 0.90.0.
> 
> I have a simple mapping defined like this:
> 
> {  
> "mappings" : {  
> "user" : {  
> "properties" : {  
> "user\_name" : {  
> "type" : "string",  
> "index\_options" : "freqs",  
> "boost" : 3.0  
> },  
> "handle" : {  
> "type" : "string",  
> "index\_options" : "docs"  
> },  
> "bio" : {  
> "type" : "string",  
> "index\_options" : "freqs"  
> },  
> "location" : {  
> "type" : "geo\_point",  
> "lat\_lon" : true  
> }  
> }  
> },  
> "post" : {  
> "properties" : {  
> "text" : {  
> "type" : "string",  
> "index\_options" : "freqs"  
> },  
> "location" : {  
> "type" : "geo\_point",  
> "lat\_lon" : true  
> }  
> }  
> }  
> }  
> }
> 
> I've loaded around 50k entries into the index.
> 
> I want to be able to perform searches based on text and optionally  
> filtered by a geo\_bounding\_box.
> 
> If I issue the following search, it works beautifully:
> 
> curl -XGET localhost:9200/wotzere/\_search?pretty=1 -d '  
> {  
> "fields" : ["\_id", "\_type", "location"],  
> "from" : 0,  
> "size" : 20,  
> "query" : {  
> "match": {  
> "\_all" : "chill ice lodge"  
> }  
> }  
> }'
> 
> It returns:
> 
> {  
> "took" : 5,  
> "timed\_out" : false,  
> "\_shards" : {  
> "total" : 5,  
> "successful" : 5,  
> "failed" : 0  
> },  
> "hits" : {  
> "total" : 1170,  
> "max\_score" : 2.2864966,  
> "hits" : [ {  
> "\_index" : "wotzere",  
> "\_type" : "user",  
> "\_id" : "80248",  
> "\_score" : 2.2864966,  
> "fields" : {  
> "location" : ["145.0450", "-37.8232"]  
> }  
> }, {  
> "\_index" : "wotzere",  
> "\_type" : "user",  
> "\_id" : "66694",  
> "\_score" : 1.3186983,  
> "fields" : {  
> "location" : ["144.9679", "-37.8205"]  
> }  
> }, {  
> "\_index" : "wotzere",  
> "\_type" : "user",  
> "\_id" : "72829",  
> "\_score" : 0.76025414,  
> "fields" : {  
> "location" : ["151.3003", "-32.7730"]  
> }  
> }, {  
> "\_index" : "wotzere",  
> "\_type" : "user",  
> "\_id" : "70022",  
> "\_score" : 0.6828435,  
> "fields" : {  
> "location" : ["150.2991", "-34.6497"]  
> }  
> }, {  
> "\_index" : "wotzere",  
> "\_type" : "post",  
> "\_id" : "138114",  
> "\_score" : 0.52798617,  
> "fields" : {  
> "location" : ["130.8392", "-12.4630"]  
> }  
> }, {  
> :  
> } ]  
> }  
> }
> 
> For the life of me I can't get a geo\_bounding\_box filter to work - even on  
> its own. Would some kind soul please point me in the right direction by  
> incorporating a bounding box of (lat, long) tl =\> (-10, 110), br =\> (-44,  
> 155) into my original search criteria?
> 
> One thing that's not clear to me. If I have a field called "location" in  
> both my types (user, post), do I need to specify both in separate  
> geo\_bounding\_box filters or can I do it with a single, unqualified filter  
> (sort of like what I'm doing with the "\_all" of the original criteria)?
> 
> Thanks so much.
> 
> Steve

--  
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: ![Steve\_Baldwin](https://avatars.discourse-cdn.com/v4/letter/s/fbc32d/32.png) [@Steve\_Baldwin](https://discuss.elastic.co/u/Steve_Baldwin)
#### Post date: [May 6, 2013, 6:42pm UTC](https://discuss.elastic.co/t/my-problem-with-geo-bounding-box/11825/3 "2013-05-06T18:42:34Z")

</div>

Fantastic !! That was very helpful.

Thank you very much Florian.

Steve

On Monday, May 6, 2013 9:42:05 PM UTC+10, Florian Schilling wrote:

> Hi Steve,
> 
> you can setup your geo\_bounding\_box filter by just adding a  
> geo\_bounding\_box filter:
> 
> curl -XGET '[http://127.0.0.1:9200/posts/\_search?pretty=true](http://127.0.0.1:9200/posts/_search?pretty=true)' -d '{
> 
> ```
> "fields" : ["_id", "_type", "location"],
> "from" : 0,
> "size" : 20,
> "query" : {
> "match": {
> "_all" : "chilling"
> }
> },
> 
> "filter" : {
> "geo_bounding_box" : {
> "location" : {
> "top_left" : {
> "lat" : -10.0,
> "lon" : 110.0
> },
> "bottom_right" : {
> "lat" : -44.0,
> "lon" : 155
> }
> }
> }
> }
> 
> ```
> 
> }'
> 
> I hope, this will help you,  
> Florian
> 
> On Monday, May 6, 2013 7:03:04 AM UTC+2, Steve Baldwin wrote:
> 
> > Hi,
> > 
> > I'm a new es user but love what I've seen so far. I'm using 0.90.0.
> > 
> > I have a simple mapping defined like this:
> > 
> > {  
> > "mappings" : {  
> > "user" : {  
> > "properties" : {  
> > "user\_name" : {  
> > "type" : "string",  
> > "index\_options" : "freqs",  
> > "boost" : 3.0  
> > },  
> > "handle" : {  
> > "type" : "string",  
> > "index\_options" : "docs"  
> > },  
> > "bio" : {  
> > "type" : "string",  
> > "index\_options" : "freqs"  
> > },  
> > "location" : {  
> > "type" : "geo\_point",  
> > "lat\_lon" : true  
> > }  
> > }  
> > },  
> > "post" : {  
> > "properties" : {  
> > "text" : {  
> > "type" : "string",  
> > "index\_options" : "freqs"  
> > },  
> > "location" : {  
> > "type" : "geo\_point",  
> > "lat\_lon" : true  
> > }  
> > }  
> > }  
> > }  
> > }
> > 
> > I've loaded around 50k entries into the index.
> > 
> > I want to be able to perform searches based on text and optionally  
> > filtered by a geo\_bounding\_box.
> > 
> > If I issue the following search, it works beautifully:
> > 
> > curl -XGET localhost:9200/wotzere/\_search?pretty=1 -d '  
> > {  
> > "fields" : ["\_id", "\_type", "location"],  
> > "from" : 0,  
> > "size" : 20,  
> > "query" : {  
> > "match": {  
> > "\_all" : "chill ice lodge"  
> > }  
> > }  
> > }'
> > 
> > It returns:
> > 
> > {  
> > "took" : 5,  
> > "timed\_out" : false,  
> > "\_shards" : {  
> > "total" : 5,  
> > "successful" : 5,  
> > "failed" : 0  
> > },  
> > "hits" : {  
> > "total" : 1170,  
> > "max\_score" : 2.2864966,  
> > "hits" : [ {  
> > "\_index" : "wotzere",  
> > "\_type" : "user",  
> > "\_id" : "80248",  
> > "\_score" : 2.2864966,  
> > "fields" : {  
> > "location" : ["145.0450", "-37.8232"]  
> > }  
> > }, {  
> > "\_index" : "wotzere",  
> > "\_type" : "user",  
> > "\_id" : "66694",  
> > "\_score" : 1.3186983,  
> > "fields" : {  
> > "location" : ["144.9679", "-37.8205"]  
> > }  
> > }, {  
> > "\_index" : "wotzere",  
> > "\_type" : "user",  
> > "\_id" : "72829",  
> > "\_score" : 0.76025414,  
> > "fields" : {  
> > "location" : ["151.3003", "-32.7730"]  
> > }  
> > }, {  
> > "\_index" : "wotzere",  
> > "\_type" : "user",  
> > "\_id" : "70022",  
> > "\_score" : 0.6828435,  
> > "fields" : {  
> > "location" : ["150.2991", "-34.6497"]  
> > }  
> > }, {  
> > "\_index" : "wotzere",  
> > "\_type" : "post",  
> > "\_id" : "138114",  
> > "\_score" : 0.52798617,  
> > "fields" : {  
> > "location" : ["130.8392", "-12.4630"]  
> > }  
> > }, {  
> > :  
> > } ]  
> > }  
> > }
> > 
> > For the life of me I can't get a geo\_bounding\_box filter to work - even  
> > on its own. Would some kind soul please point me in the right direction by  
> > incorporating a bounding box of (lat, long) tl =\> (-10, 110), br =\> (-44,  
> > 155) into my original search criteria?
> > 
> > One thing that's not clear to me. If I have a field called "location" in  
> > both my types (user, post), do I need to specify both in separate  
> > geo\_bounding\_box filters or can I do it with a single, unqualified filter  
> > (sort of like what I'm doing with the "\_all" of the original criteria)?
> > 
> > Thanks so much.
> > 
> > Steve

--  
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:38am UTC](https://discuss.elastic.co/t/my-problem-with-geo-bounding-box/11825/4 "2017-07-06T02:38:03Z")

</div>


