Filter geo_distance_range


(tommy) #1

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"

curl -XPOST "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" -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" -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
}
]
}
}
}
}
';


(Shay Banon) #2

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"

curl -XPOST "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" -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" -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
}
]
}
}
}
}
';


(system) #3