版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u013476435/article/details/90675753
在使用es 5.3时,想使用geo_distance_range实现环形搜索。
geo_distance_range的介绍如下:
在使用时,想去将自己的数据导入到es中并添加上索引,这里我的位置字段是position。
JestResult jestResult = jestClient.execute(new CreateIndex.Builder("igomomemberinfo").build());
然后再将index上添加indexMapping
String mappingString = "{\"" + "igomomemberinfo" + "\":{\"properties\":{\"position\":{\"type\":\"geo_point\", \"index\":\"true\"}}}}"; PutMapping.Builder builder = new PutMapping.Builder("igomomemberinfo", "igomomemberinfo", mappingString); try { JestResult jestResult = jestClient.execute(builder.build()); System.out.println("createIndexMapping result:{}" + jestResult.isSucceeded()); if (!jestResult.isSucceeded()) { System.err.println("settingIndexMapping error:{}" + jestResult.getErrorMessage()); } } catch (IOException e) { e.printStackTrace(); }
使用语句查询
POST http://192.168.53.92:9200/igomomemberinfo/_search { "query": { "bool": { "must": { "match_all": {} }, "filter": { "geo_distance_range": { "position": [ 116.313349, 39.95041 ] } } } } }
返回提示:
{ "error": { "root_cause": [{ "type": "query_shard_exception", "reason": "[geo_distance_range] queries are no longer supported for geo_point field types. Use geo_distance sort or aggregations", "index_uuid": "8dqfsTbSTLquW5d5B7l3Cw", "index": "igomomemberinfo" }], "type": "search_phase_execution_exception", "reason": "all shards failed", "phase": "query", "grouped": true, "failed_shards": [{ "shard": 0, "index": "igomomemberinfo", "node": "0UzWcOlOSh-WGCLVsTpAWA", "reason": { "type": "query_shard_exception", "reason": "[geo_distance_range] queries are no longer supported for geo_point field types. Use geo_distance sort or aggregations", "index_uuid": "8dqfsTbSTLquW5d5B7l3Cw", "index": "igomomemberinfo" } }], "caused_by": { "type": "query_shard_exception", "reason": "[geo_distance_range] queries are no longer supported for geo_point field types. Use geo_distance sort or aggregations", "index_uuid": "8dqfsTbSTLquW5d5B7l3Cw", "index": "igomomemberinfo" } }, "status": 400 }
返回400为错误。因5.x不支持geo_distance_range了,建议使用geo_distance
文章来源: https://blog.csdn.net/u013476435/article/details/90675753