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

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章