Wednesday 15 February 2012

Elasticsearch spatial queries (within particular radius) -



Elasticsearch spatial queries (within particular radius) -

i using elasticsearch application. in trying run spatial queries given lat,long couldn't result....

my index looks this:

"hits": { "total": 1, "max_score": 1, "hits": [ { "_index": "pca_beta_v1", "_type": "place", "_id": "8neiquwqtmmclpo7yu6txa", "_score": 1, "_source": { "idmap70": 305215, "id_0": 356, "id_1": "33", "id_2": "602222", "id_3": "566693", "id_4": "628343548", "name_0": "india", "name_1": "aaaaa", "name_2": "bbbb", "name_3": "cccc", "name_4": "nnnnnn", "latitude": 13.534991, "longitude": 80.015182, "key": "ooooooo", "leveltype": "ttttt" }}] }

i tried next query:

get bdrtfd/_search/ { "query": { "match_all": {} }, "filter": { "geo_distance": { "location": { "lat": "13.534991", "lon": "80.015182" }, "distance": "3km" } } }

but getting error:

{ "error": "searchphaseexecutionexception[failed execute phase [query_fetch], shards failed; shardfailures {[ppp8dqk9qast8h9rukamsq][pca_beta_v1][0]: searchparseexception[[pca_beta_v1][0]: query[constantscore(*:*)],from[-1],size[-1]: parse failure [failed parse source [{\n \"query\": {\n \"match_all\": {}\n },\n \"filter\": {\n \"geo_distance\": {\n \"location\": {\n \"lat\": \"13.534991\",\n \"lon\": \"80.015182\"\n },\n \"distance\": \"3km\"\n }\n }\n}\n]]]; nested: queryparsingexception[[pca_beta_v1] failed find geo_point field [location]]; }]", "status": 400 }

your "latitude": 13.534991, "longitude": 80.015182 fields in mapping need have different kind of type able used in geo location computations. needs 1 field, not two, , must this:

"location": { "type": "geo_point" }

and then, when indexing, specify this:

{"location":{"lat":13.534991,"lon":80.015182}}

and query work.

elasticsearch

No comments:

Post a Comment