Elasticsearch 5.X系列不再支持geo_distance_range

匿名 (未验证) 提交于 2019-12-02 23:36:01
版权声明:本文为博主原创文章,未经博主允许不得转载。 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
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!