# Filter geo\_distance\_range

**URL:** <https://discuss.elastic.co/t/filter-geo-distance-range/6783>\
**Category:** Elasticsearch\
**Created:** [February 22, 2012, 11:53am UTC](https://discuss.elastic.co/t/filter-geo-distance-range/6783 "2012-02-22T11:53:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tommy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tommy/32/2980_2.png) [@tommy](https://discuss.elastic.co/u/tommy)\
**Post date:** [February 22, 2012, 11:53am UTC](https://discuss.elastic.co/t/filter-geo-distance-range/6783/1 "2012-02-22T11:53:17Z")

</div>

Hi!

Im trying to add a geo\_distance\_range filter to my query, but I get a  
error message NumberFormatException[For input string: "0km"].

Below is the requests i'm running. Can anyone see what the problem  
might be?

* * *

curl -XPOST "[http://localhost:9200/app?pretty=true](http://localhost:9200/app?pretty=true)"

curl -XPOST "[http://localhost:9200/app/item/\_mapping?pretty=true](http://localhost:9200/app/item/_mapping?pretty=true)" -d '  
{  
"item" : {  
"properties" : {  
"name" : { "type" : "string" },  
"description" : { "type" : "string" },  
"created" : { "type" : "date" },  
"location" : {  
"properties" : {  
"location" : { "type" : "geo\_point" }  
}  
},  
"is\_proaccount" : { "type" : "integer" },  
"is\_given\_away" : { "type" : "integer" },  
"is\_private" : { "type" : "integer" },  
"friends" : { "type" : "integer", "index\_name" :  
"friend" }  
}  
}  
}  
';

curl -XPOST "[http://localhost:9200/app/item/\_bulk?pretty=true](http://localhost:9200/app/item/_bulk?pretty=true)" -d '  
{"create":{"\_id":1}}  
{"name":"Testing  
1","description":"Test1","created":"2012-02-20T12:21:30","location":  
{"location":  
{"lat":"59.919914","lon":"10.753414"}},"is\_proaccount":"0","is\_given\_away":"0","is\_private":  
1,"friends":[4,6,8]}  
{"create":{"\_id":2}}  
{"name":"Testing  
2","description":"Test2","created":"2012-02-23T09:00:00","location":  
{"location":  
{"lat":"59.919914","lon":"10.753414"}},"is\_proaccount":"0","is\_given\_away":"0","is\_private":  
1,"friends":[4,6,8]}  
{"create":{"\_id":3}}  
{"name":"Testing 3","description":"Test  
3","created":"2011-09-22T14:51:08","location":{"location":  
{"lat":"59.925091","lon":"10.750004"}},"is\_proaccount":"1","is\_given\_away":"0","is\_private":  
1,"friends":[4,6,8]}  
{"create":{"\_id":4}}  
{"name":"Test4","description":"Test3","created":"2011-10-14T11:00:13","location":  
{"location":  
{"lat":"59.925117","lon":"10.749977"}},"is\_proaccount":"1","is\_given\_away":"0","is\_private":  
1,"friends":[4,6,8]}  
{"create":{"\_id":5}}  
{"name":"Test5","description":"Test5","created":"2011-10-14T11:11:57","location":  
{"location":  
{"lat":"59.925098","lon":"10.749986"}},"is\_proaccount":"1","is\_given\_away":"0","is\_private":  
1,"friends":[4,6,8]}  
';

curl -XPOST "[http://localhost:9200/app/item/\_search?pretty=true](http://localhost:9200/app/item/_search?pretty=true)" -d '  
{  
"from": 0,  
"size": 30,  
"sort": {  
"\_geo\_distance": {  
"location": {  
"lat": 59.919922,  
"lon": 10.753627  
},  
"order": "asc",  
"unit": "km"  
}  
},  
"filter": {  
"or": [  
{  
"bool": {  
"must": [  
{  
"term": {  
"friends": 4  
}  
}  
]  
}  
},  
{  
"bool": {  
"must": [  
{  
"term": {  
"is\_private": 0  
}  
}  
]  
}  
}  
],  
"geo\_distance\_range": {  
"from": "0km",  
"to": "30km",  
"location": {  
"lat": 59.919922,  
"lon": 10.753627  
}  
}  
},  
"query": {  
"query\_string": {  
"query": "Snus"  
}  
},  
"facets": {  
"items\_distribution": {  
"geo\_distance": {  
"location": {  
"lat": 59.919922,  
"lon": 10.753627  
},  
"ranges": [  
{  
"from" : 0,  
"to": 20  
},  
{  
"from": 20,  
"to": 50  
},  
{  
"from": 50,  
"to": 180  
},  
{  
"from": 80  
}  
]  
}  
}  
}  
}  
';

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [February 26, 2012, 9:47am UTC](https://discuss.elastic.co/t/filter-geo-distance-range/6783/2 "2012-02-26T09:47:58Z")

</div>

Your geo\_distance\_range is outside the "or" filter, so you end up having "or" and then on the same level "geo\_distance\_range" filter. Do you want to "and" the two? If so, wrap it in an and filter. (also, can you gist recreations? they loose formatting with mails).

On Wednesday, February 22, 2012 at 1:53 PM, tommy wrote:

> Hi!
> 
> Im trying to add a geo\_distance\_range filter to my query, but I get a  
> error message NumberFormatException[For input string: "0km"].
> 
> Below is the requests i'm running. Can anyone see what the problem  
> might be?
> 
> * * *
> 
> curl -XPOST "[http://localhost:9200/app?pretty=true](http://localhost:9200/app?pretty=true)"
> 
> curl -XPOST "[http://localhost:9200/app/item/\_mapping?pretty=true](http://localhost:9200/app/item/_mapping?pretty=true)" -d '  
> {  
> "item" : {  
> "properties" : {  
> "name" : { "type" : "string" },  
> "description" : { "type" : "string" },  
> "created" : { "type" : "date" },  
> "location" : {  
> "properties" : {  
> "location" : { "type" : "geo\_point" }  
> }  
> },  
> "is\_proaccount" : { "type" : "integer" },  
> "is\_given\_away" : { "type" : "integer" },  
> "is\_private" : { "type" : "integer" },  
> "friends" : { "type" : "integer", "index\_name" :  
> "friend" }  
> }  
> }  
> }  
> ';
> 
> curl -XPOST "[http://localhost:9200/app/item/\_bulk?pretty=true](http://localhost:9200/app/item/_bulk?pretty=true)" -d '  
> {"create":{"\_id":1}}  
> {"name":"Testing  
> 1","description":"Test1","created":"2012-02-20T12:21:30","location":  
> {"location":  
> {"lat":"59.919914","lon":"10.753414"}},"is\_proaccount":"0","is\_given\_away":"0","is\_private":  
> 1,"friends":[4,6,8]}  
> {"create":{"\_id":2}}  
> {"name":"Testing  
> 2","description":"Test2","created":"2012-02-23T09:00:00","location":  
> {"location":  
> {"lat":"59.919914","lon":"10.753414"}},"is\_proaccount":"0","is\_given\_away":"0","is\_private":  
> 1,"friends":[4,6,8]}  
> {"create":{"\_id":3}}  
> {"name":"Testing 3","description":"Test  
> 3","created":"2011-09-22T14:51:08","location":{"location":  
> {"lat":"59.925091","lon":"10.750004"}},"is\_proaccount":"1","is\_given\_away":"0","is\_private":  
> 1,"friends":[4,6,8]}  
> {"create":{"\_id":4}}  
> {"name":"Test4","description":"Test3","created":"2011-10-14T11:00:13","location":  
> {"location":  
> {"lat":"59.925117","lon":"10.749977"}},"is\_proaccount":"1","is\_given\_away":"0","is\_private":  
> 1,"friends":[4,6,8]}  
> {"create":{"\_id":5}}  
> {"name":"Test5","description":"Test5","created":"2011-10-14T11:11:57","location":  
> {"location":  
> {"lat":"59.925098","lon":"10.749986"}},"is\_proaccount":"1","is\_given\_away":"0","is\_private":  
> 1,"friends":[4,6,8]}  
> ';
> 
> curl -XPOST "[http://localhost:9200/app/item/\_search?pretty=true](http://localhost:9200/app/item/_search?pretty=true)" -d '  
> {  
> "from": 0,  
> "size": 30,  
> "sort": {  
> "\_geo\_distance": {  
> "location": {  
> "lat": 59.919922,  
> "lon": 10.753627  
> },  
> "order": "asc",  
> "unit": "km"  
> }  
> },  
> "filter": {  
> "or": [  
> {  
> "bool": {  
> "must": [  
> {  
> "term": {  
> "friends": 4  
> }  
> }  
> ]  
> }  
> },  
> {  
> "bool": {  
> "must": [  
> {  
> "term": {  
> "is\_private": 0  
> }  
> }  
> ]  
> }  
> }  
> ],  
> "geo\_distance\_range": {  
> "from": "0km",  
> "to": "30km",  
> "location": {  
> "lat": 59.919922,  
> "lon": 10.753627  
> }  
> }  
> },  
> "query": {  
> "query\_string": {  
> "query": "Snus"  
> }  
> },  
> "facets": {  
> "items\_distribution": {  
> "geo\_distance": {  
> "location": {  
> "lat": 59.919922,  
> "lon": 10.753627  
> },  
> "ranges": [  
> {  
> "from" : 0,  
> "to": 20  
> },  
> {  
> "from": 20,  
> "to": 50  
> },  
> {  
> "from": 50,  
> "to": 180  
> },  
> {  
> "from": 80  
> }  
> ]  
> }  
> }  
> }  
> }  
> ';

---

<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:38am UTC](https://discuss.elastic.co/t/filter-geo-distance-range/6783/3 "2017-07-06T03:38:17Z")

</div>


