Quantcast

Problem with geo_distance filter

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Problem with geo_distance filter

Sean Bowman
I tried following the examples, but I can't seem to make a
geo_distance (or any geo filter) work, using 0.10.0.  Here's my steps,
after starting the search index:

$ curl -XPUT 'http://localhost:9200/test'

$ curl -XPUT 'http://localhost:9200/test/pins/1' -d '{
    "pin" : {
        "location" : {
            "lat" : 40.12,
            "lon" : -71.34
        },
        "tag" : ["food", "family"],
        "text" : "my favorite family restaurant"
    }
}'

$ curl -XGET 'http://localhost:9200/test/pins/_search' -d '
{ "query" : {
    "filtered" : {
        "query" : {
            "field" : { "text" : "restaurant" }
        },
        "filter" : {
            "geo_distance" : {
                "distance" : "12km",
                "pin.location" : {
                    "lat" : 40,
                    "lon" : -70
                }
            }
        }
    }
  }
}'

The result:

  {"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":
0,"max_score":null,"hits":[]}}

Can anyone tell me what I'm doing wrong here?

Thanks.

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Problem with geo_distance filter

kimchy
Administrator
Hey,

  The distance between the mentioned point is 114.94km, so you need to broaden your search. A few pointers:

1. After indexing data, you will see the changes after 1 second (give or take). If you test (i.e. execute fast consecutive curl requests, execute refresh before the search).
2. If you want to check some distances, you can do a match_all query and sort by geo_distance, this will give you the actual distances (sort values are returned as part of the search): http://www.elasticsearch.com/docs/elasticsearch/rest_api/search/sort/#Geo_Distance_Sorting.

-shay.banon 

On Fri, Sep 24, 2010 at 10:03 PM, Sean Bowman <[hidden email]> wrote:
I tried following the examples, but I can't seem to make a
geo_distance (or any geo filter) work, using 0.10.0.  Here's my steps,
after starting the search index:

$ curl -XPUT 'http://localhost:9200/test'

$ curl -XPUT 'http://localhost:9200/test/pins/1' -d '{
   "pin" : {
       "location" : {
           "lat" : 40.12,
           "lon" : -71.34
       },
       "tag" : ["food", "family"],
       "text" : "my favorite family restaurant"
   }
}'

$ curl -XGET 'http://localhost:9200/test/pins/_search' -d '
{ "query" : {
   "filtered" : {
       "query" : {
           "field" : { "text" : "restaurant" }
       },
       "filter" : {
           "geo_distance" : {
               "distance" : "12km",
               "pin.location" : {
                   "lat" : 40,
                   "lon" : -70
               }
           }
       }
   }
 }
}'

The result:

 {"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":
0,"max_score":null,"hits":[]}}

Can anyone tell me what I'm doing wrong here?

Thanks.


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Problem with geo_distance filter

Sean Bowman
Changing the range worked...finally! *fireworks*  Thank you.  I should
have checked that.

The sort idea is a good one too.  Thanks for that reference.  I can't
tell you how refreshing it is to have someone on a mailing list point
me at the correct documentation, rather than just tell me to read
everything on the entire site or type keywords into Google.  :-)

Just so you know, this is the example from your blog article and the
geo_distance filter doc on the web site.  You might want to update the
documentation you've got up there and increase that "12km" to
"200km".  There's also a typo in the sample JSON:  no comma after the
"distance" : "12km" line.  And while not technically a error, on the
sort documentation page, your query centers on [-40, 70], while your
examples were always [40, -70].  For consistency, you might want to
swap the negative there.  Took me a second of wondering how I got
16000+km when you found 114km, before I realized the signs were
reversed.

This is only day two of using ElasticSearch, and I'm loving the
product.  Outstanding work.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Problem with geo_distance filter

kimchy
Administrator
Hi,

   Thanks for the doc notes, pushed a fix for that.

-shay.banon

On Fri, Sep 24, 2010 at 11:37 PM, Sean Bowman <[hidden email]> wrote:
Changing the range worked...finally! *fireworks*  Thank you.  I should
have checked that.

The sort idea is a good one too.  Thanks for that reference.  I can't
tell you how refreshing it is to have someone on a mailing list point
me at the correct documentation, rather than just tell me to read
everything on the entire site or type keywords into Google.  :-)

Just so you know, this is the example from your blog article and the
geo_distance filter doc on the web site.  You might want to update the
documentation you've got up there and increase that "12km" to
"200km".  There's also a typo in the sample JSON:  no comma after the
"distance" : "12km" line.  And while not technically a error, on the
sort documentation page, your query centers on [-40, 70], while your
examples were always [40, -70].  For consistency, you might want to
swap the negative there.  Took me a second of wondering how I got
16000+km when you found 114km, before I realized the signs were
reversed.

This is only day two of using ElasticSearch, and I'm loving the
product.  Outstanding work.

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Problem with geo_distance filter

dcosta72
I have been following the examples (0.15.2 and even tried 0.10.0) too and I can not get the geo_distance filter to work either.

Any help will be greatly appreciated.

This is what I am posting:

$ curl -XPUT 'http://localhost:9200/test6/pins/1' -d '{
   "pin" : {
       "location" : {
           "lat" : 40.12,
           "lon" : -71.34
       },
       "tag" : ["food", "family"],
       "text" : "my favorite family restaurant"
   }
}'

$ curl -XPUT 'http://localhost:9200/test6/_mapping' -d '
{            
    "pin" : {
        "properties" : {
            "location" : {
                "type" : "geo_point"
            }
        }                    
    }                                
}'

$ curl -XGET 'http://localhost:9200/test6/pins/_search' -d '
{ "query" : {
   "filtered" : {
       "query" : {
            "match_all" : {}
        },
       "filter" : {
           "geo_distance" : {
               "distance" : "1025km",
               "pin.location" : {
                   "lat" : 40,
                   "lon" : -70
               }
           }
       }
   }
 }
}'
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Problem with geo_distance filter

kimchy
Administrator
Make sure to put the mappings before you index the document.

On Thursday, March 24, 2011 at 1:16 AM, dcosta72 wrote:

I have been following the examples (0.15.2 and even tried 0.10.0) too and I
can not get the geo_distance filter to work either.

Any help will be greatly appreciated.

This is what I am posting:

$ curl -XPUT 'http://localhost:9200/test6/pins/1' -d '{
"pin" : {
"location" : {
"lat" : 40.12,
"lon" : -71.34
},
""tag" : ["food", "family"],
"text" : "my favorite family restaurant"
}
}'

$ curl -XPUT 'http://localhost:9200/test6/_mapping' -d '
{
"pin" : {
"properties" : {
"location" : {
"type" : "geo_point"
}
}}
}
}'

$ curl -XGET 'http://localhost:9200/test6/pins/_search' -d '
{ "query" : {
"filtered" : {
"query" : {
"match_all" : {}
},
"filter" : {
"geo_distance" : {
""distance" : "1025km",
"pin.location" : {
"lat" : 40,
"lon" : -70
}
}
}
}
}
}'


--
View this message in context: http://elasticsearch-users.115913.n3.nabble.com/Problem-with-geo-distance-filter-tp1576354p2722899.html
Sent from the ElasticSearch Users mailing list archive at Nabble.com.

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Problem with geo_distance filter

dcosta72
Thanks Shay,

Unfortunately I can not get it working. I have tried many different approaches and it just doesn't work for me... I would really appreciate a full working example on 0.15.2, with mapping included.

I am new to ES and I would like to use it for a project I am working on, but I need the geo_distance search to work...

Apologies if I am missing something obvious. I have spent already a few days with this...


Thanks again.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Problem with geo_distance filter

dcosta72
I got it working. I got slightly confused with the entities involved.

Thanks again for your response.


ES is an outstanding product. Excellent work.

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Problem with geo_distance filter

kimchy
Administrator
In reply to this post by dcosta72
gist what you are doing, we can take it from there.

On Monday, March 28, 2011 at 1:34 AM, dcosta72 wrote:

Thanks Shay,

Unfortunately I can not get it working. I have tried many different
approaches and it just doesn't work for me... I would really appreciate a
full working example on 0.15.2, with mapping included.

I am new to ES and I would like to use it for a project I am working on, but
I need the geo_distance search to work...

Apologies if I am missing something obvious. I have spent already a few days
with this...


Thanks again.

--
View this message in context: http://elasticsearch-users.115913.n3.nabble.com/Problem-with-geo-distance-filter-tp1576354p2741050.html
Sent from the ElasticSearch Users mailing list archive at Nabble.com.

Loading...