Elasticsearch 5.X系列不再支持geo_distance_range

在使用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

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值