Reputation: 7386
Here's my mapping:
$ curl -XGET http://localhost:9200/test-index/dev/_mapping?pretty
{
"test-index" : {
"mappings" : {
"dev" : {
"properties" : {
"Coordinates" : {
"type" : "double"
},
"DisplayName" : {
"type" : "string"
},
"Location" : {
"type" : "string"
},
"RawLocation" : {
"type" : "string"
},
"Reputation" : {
"type" : "string"
}
}
}
}
}
}
My goal is to run a geo distance query on Coordinates.
I use this coordinate format:
"location": [ -73.983, 40.719 ]
Here are a few results:
$ curl -XGET http://localhost:9200/test-index/dev/_search?pretty
...
{
"_index" : "test-index",
"_type" : "dev",
"_id" : "Arindam Nayak",
"_score" : 1.0,
"_source":{"RawLocation": "Pune, India", "Reputation": "101", "DisplayName": "Arindam Nayak", "Location": "Pune, Maharashtra 411001, India", "Coordinates": [73.8567437, 18.5204303]}
},
...
I tried many ways to get a list of hits from around a coordinate but to no avail:
$ curl -XGET http://localhost:9200/test-index/dev/_search -d '
{
"filter" : {
"geo_distance" : {
"distance" : "20km",
“Coordinates : {
"lat" : 40.00,
"lon" : 9.00
}
}
}
}
'
Here's the sad result:
"error":"SearchPhaseExecutionException[Failed to execute phase [query], all shards failed; shardFailures {[6W3CA5U5TqStabDolHcIng][test-index][0]: SearchParseException[[test-index][0]: from[-1],size[-1]: Parse Failure [Failed to parse source [\n{\n\"filter\" : {\n \"geo_distance\" : {\n \"distance\" : \"20km\",\n “Coordinates : {\n \"lat\" : 40.00,\n \"lon\" : 9.00\n }\n }\n }\n }\n]]]; nested: QueryParsingException[[test-index] failed to find geo_point field [“Coordinates]]; }{[6W3CA5U5TqStabDolHcIng][test-index][1]: SearchParseException[[test-index][1]: from[-1],size[-1]: Parse Failure [Failed to parse source [\n{\n\"filter\" : {\n \"geo_distance\" : {\n \"distance\" : \"20km\",\n “Coordinates : {\n \"lat\" : 40.00,\n \"lon\" : 9.00\n }\n }\n }\n }\n]]]; nested: QueryParsingException[[test-index] failed to find geo_point field [“Coordinates]]; }{[6W3CA5U5TqStabDolHcIng][test-index][2]: SearchParseException[[test-index][2]: from[-1],size[-1]: Parse Failure [Failed to parse source [\n{\n\"filter\" : {\n \"geo_distance\" : {\n \"distance\" : \"20km\",\n “Coordinates : {\n \"lat\" : 40.00,\n \"lon\" : 9.00\n }\n }\n }\n }\n]]]; nested: QueryParsingException[[test-index] failed to find geo_point field [“Coordinates]]; }{[6W3CA5U5TqStabDolHcIng][test-index][3]: SearchParseException[[test-index][3]: from[-1],size[-1]: Parse Failure [Failed to parse source [\n{\n\"filter\" : {\n \"geo_distance\" : {\n \"distance\" : \"20km\",\n “Coordinates : {\n \"lat\" : 40.00,\n \"lon\" : 9.00\n }\n }\n }\n }\n]]]; nested: QueryParsingException[[test-index] failed to find geo_point field [“Coordinates]]; }{[6W3CA5U5TqStabDolHcIng][test-index][4]: SearchParseException[[test-index][4]: from[-1],size[-1]: Parse Failure [Failed to parse source [\n{\n\"filter\" : {\n \"geo_distance\" : {\n \"distance\" : \"20km\",\n “Coordinates : {\n \"lat\" : 40.00,\n \"lon\" : 9.00\n }\n }\n }\n }\n]]]; nested: QueryParsingException[[test-index] failed to find geo_point field [“Coordinates]]; }]","status":400}
Any help?
Upvotes: 0
Views: 143
Reputation: 12672
As the error stats, ES is not able to find Coordinates
field which is of type geo_point
. You need map Coordinates
field as geo_point in order to perform any location query.
{
"test-index": {
"mappings": {
"dev": {
"properties": {
"Coordinates": {
"type": "geo_point" <--- change type from double to geo_point
},
"DisplayName": {
"type": "string"
},
"Location": {
"type": "string"
},
"RawLocation": {
"type": "string"
},
"Reputation": {
"type": "string"
}
}
}
}
}
}
Since you are using an array format
you need to insert coordinates as [lon, lat]
.
You would have to reindex
your data. After that your query will work.
Hope this helps!
Upvotes: 1