这是我的映射:
$ 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"
}
}
}
}
}
}
我的目标是在“坐标”上运行地理距离查询。
我使用以下坐标格式:
"location": [ -73.983, 40.719 ]
以下是一些结果:
$ 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]}
},
...
我尝试了多种方法来获取坐标周围的命中列表,但无济于事:
$ curl -XGET http://localhost:9200/test-index/dev/_search -d '
{
"filter" : {
"geo_distance" : {
"distance" : "20km",
“Coordinates : {
"lat" : 40.00,
"lon" : 9.00
}
}
}
}
'
这是可悲的结果:
"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}
有什么帮助吗?
最佳答案
作为错误统计信息,ES无法找到类型为Coordinates
的geo_point
字段。您需要将 map Coordinates
字段作为geo_point来执行任何位置查询。
{
"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"
}
}
}
}
}
}
由于您使用的是
array format
,因此需要将坐标插入为[lon, lat]
。您将不得不
reindex
您的数据。之后,您的查询将起作用。希望这可以帮助!
关于rest - Elasticsearch:地理位置距离查询错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35120066/