Whats wrong with this geo_shape elasticsearch query? -


i trying geo_shape query document location (see example document below) , getting nullpointerexception when trying execute elasticsearch via chrome addon "sense". exact results @ bottom of question...

any on getting right geo_shape query work appreciated.

query throwing exception

{    "query": {               "geo_shape": {         "location": {            "shape": {               "type": "polygon",                "coordinates": [[-87.6363976, 41.8772528], [-87.6363976, 41.8902152],[-87.62131840000001, 41.8902152], [-87.62131840000001, 41.8772528], [-87.6363976, 41.8772528]]            }         }        }      }  } 

example document

{     "id": 1483,     "name": "independance day movie day",     "location": [               41.9527,               -87.725            ] } 

exact results sense

{ "error": "searchphaseexecutionexception[failed execute phase [query_fetch], shards failed; shardfailures {[qfv-xnqxsi2oatfvmnvo8w][dev][0]: searchparseexception[[dev][0]: from[-1],size[-1]: parse failure [failed parse source [{\n   \"query\": { \n       \"geo_shape\": {\n          \"location\": {\n             \"shape\": {\n                \"type\": \"polygon\", \n                \"coordinates\": [[-87.6363976, 41.8772528], [-87.6363976, 41.8902152],[-87.62131840000001, 41.8902152], [-87.62131840000001, 41.8772528], [-87.6363976, 41.8772528]]\n             }\n          }\n          \n       \n       }\n        \n   \n   }\n}\n]]]; nested: nullpointerexception; }]", "status": 400 } 

there's 2 things wrong here. first, location field should object has type , coordinates field, expect should be:

"location": {   "type" : "point",   "coordinates" : [ 41.9527, -87.725 ] } 

note using array format, specifying them (x, y) or (longitude, latitude).

secondly, query close being correct, requires level of array polygon:

{   "query": {              "geo_shape": {       "location": {         "shape": {           "type": "polygon",            "coordinates": [               [[-87.6363976, 41.8772528], [-87.6363976, 41.8902152],                [-87.62131840000001, 41.8902152], [-87.62131840000001, 41.8772528],                [-87.6363976, 41.8772528]]           ]         }       }     }   } } 

the purpose of layer of nesting allows inner polygons specified things holes. also, values in polygon not contain point searching for, , (x, y) values reversed 1 of them regardless.

just in case have not done so, required set geoshape mapping in order work (where type_name specific index's type, such curl -xget localhost:9200/index/type):

{   "mappings" : {     "type_name" : {       "properties" : {         "id" : { "type" : "long" },         "name" : { "type" : "string" },         "location" : { "type" : "geo_shape" }       }     }   } } 

Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -