How to apply multiple geo_distance filters to match any of multiple locations?


(Jim-2) #1

I've indexed a document like below:

curl -XPUT 'http://localhost:9200/people/person/1' -d'
{
"locations": [
{
"location": "51.0587013,-2.9499066",
"id": 1
},
{
"location": "51.38596454,-2.36162306118",
"id": 2
}
]
}'

mapped the 'location' field to geo_point with:

curl -XPUT 'http://localhost:9200/people/person/_mapping?
ignore_conflicts=true' -d'
{
"person":{
"properties": {
"locations": {
"properties": {
"location": {
"type": "geo_point"
}
}
}
}
}
}'

I want to search so I can supply several geo_points and receive
results which have (at least) one location near any of the points I
supply.

I've tried several things, none of which work, for example:

curl -XGET 'http://localhost:9200/people/person/_search' -d'
{
"query": {
"filtered": {
"filter": {
"not": {
"ids": {
"values": [
2
]
}
},
"geo_distance": {
"distance": "500mi",
"locations.location":
["51.38596452,-2.36162306116", "51.0587015,-2.9499065"]
}
}
}
}
}'

I just get an exception like:

nested: QueryParsingException[[people] [_na] filter malformed, no
field after start_object

How can I do this?

Thanks,
Jim


(Eric Jain) #2

On Mar 8, 7:27 am, Jim beanb...@googlemail.com wrote:

I want to search so I can supply several geo_points and receive
results which have (at least) one location near any of the points I
supply.

I don't know if the geo_distance filter supports searches for more
than one geo_point at a time. But you could combine multiple filters
using a bool 'should' filter.

Also, to handle multiple geo_points per document, you may need to
index geohashes instead of lat and long.


(egaumer) #3

You haven't specified a proper nested mapping. Have a look here -
http://www.elasticsearch.org/guide/reference/mapping/nested-type.html

-Eric

On Thursday, March 8, 2012 10:27:08 AM UTC-5, Jim wrote:

I've indexed a document like below:

curl -XPUT 'http://localhost:9200/people/person/1' -d'
{
"locations": [
{
"location": "51.0587013,-2.9499066",
"id": 1
},
{
"location": "51.38596454,-2.36162306118",
"id": 2
}
]
}'

mapped the 'location' field to geo_point with:

curl -XPUT 'http://localhost:9200/people/person/_mapping?
ignore_conflicts=truehttp://localhost:9200/people/person/_mapping?ignore_conflicts=true'
-d'
{
"person":{
"properties": {
"locations": {
"properties": {
"location": {
"type": "geo_point"
}
}
}
}
}
}'

I want to search so I can supply several geo_points and receive
results which have (at least) one location near any of the points I
supply.

I've tried several things, none of which work, for example:

curl -XGET 'http://localhost:9200/people/person/_search' -d'
{
"query": {
"filtered": {
"filter": {
"not": {
"ids": {
"values": [
2
]
}
},
"geo_distance": {
"distance": "500mi",
"locations.location":
["51.38596452,-2.36162306116", "51.0587015,-2.9499065"]
}
}
}
}
}'

I just get an exception like:

nested: QueryParsingException[[people] [_na] filter malformed, no
field after start_object

How can I do this?

Thanks,
Jim


(Jim-2) #4

Thanks, I didn't understand nesting, but I get it now.

On Mar 9, 8:58 pm, egaumer egau...@gmail.com wrote:

You haven't specified a proper nested mapping. Have a look here -http://www.elasticsearch.org/guide/reference/mapping/nested-type.html

-Eric

On Thursday, March 8, 2012 10:27:08 AM UTC-5, Jim wrote:

I've indexed a document like below:

curl -XPUT 'http://localhost:9200/people/person/1'-d'
{
"locations": [
{
"location": "51.0587013,-2.9499066",
"id": 1
},
{
"location": "51.38596454,-2.36162306118",
"id": 2
}
]
}'

mapped the 'location' field to geo_point with:

curl -XPUT 'http://localhost:9200/people/person/_mapping?
ignore_conflicts=truehttp://localhost:9200/people/person/_mapping?ignore_conflicts=true'
-d'
{
"person":{
"properties": {
"locations": {
"properties": {
"location": {
"type": "geo_point"
}
}
}
}
}
}'

I want to search so I can supply several geo_points and receive
results which have (at least) one location near any of the points I
supply.

I've tried several things, none of which work, for example:

curl -XGET 'http://localhost:9200/people/person/_search'-d'
{
"query": {
"filtered": {
"filter": {
"not": {
"ids": {
"values": [
2
]
}
},
"geo_distance": {
"distance": "500mi",
"locations.location":
["51.38596452,-2.36162306116", "51.0587015,-2.9499065"]
}
}
}
}
}'

I just get an exception like:

nested: QueryParsingException[[people] [_na] filter malformed, no
field after start_object

How can I do this?

Thanks,
Jim


(system) #5