区域检索

ESQL 为您提供了区域类型(geo_shape)数据的检索和排序功能,相关的检索函数有:

envelope 按矩形检索函数,在 WHERE 中使用
circle 按原型检索函数,在 WHERE 中使用

实例:

DROP TABLE hz_map;
CREATE TABLE hz_map.base(
    name STRING,
    location geo_shape
    -- location geo_shape {tree=quadtree, precision='1m'}
);
DESC hz_map;
DELETE hz_map;
-- ES规定数组中经度在前
BULK INTO hz_map.base(name, location()) values
('九和路', '{"type":"point", "coordinates":[120.258854,30.311865]}'),
('七堡', '{"type":"point", "coordinates":[120.247427,30.306378]}'),
('彭埠', '{"type":"point", "coordinates":[120.229892,30.300267]}'),
('杭州东站', '{"type":"point", "coordinates":[120.219328,30.297086]}'),
('闸弄口', '{"type":"point", "coordinates":[120.198991,30.290163]}'),
('打铁关', '{"type":"point", "coordinates":[120.183396,30.290849]}'),
('西湖文化广场', '{"type":"point", "coordinates":[120.172329,30.285797]}'),
('武林广场', '{"type":"point", "coordinates":[120.170892,30.278188]}'),
('凤起路', '{"type":"point", "coordinates":[120.170389,30.268238]}'),
('龙翔桥', '{"type":"point", "coordinates":[120.170604,30.260502]}'),
('定安路', '{"type":"point", "coordinates":[120.174341,30.251705]}'),
('城站', '{"type":"point", "coordinates":[120.187708,30.250083]}'),
('婺江路', '{"type":"point", "coordinates":[120.197553,30.242533]}'),
('近江', '{"type":"point", "coordinates":[120.204452,30.236542]}'),
('江陵路', '{"type":"point", "coordinates":[120.223065,30.215417]}'),
('滨和路', '{"type":"point", "coordinates":[120.223999,30.205741]}'),
('西兴', '{"type":"point", "coordinates":[120.227161,30.193256]}'),
('滨康路', '{"type":"point", "coordinates":[120.237294,30.189885]}');

FLUSH hz_map;
SELECT * FROM hz_map;

-- 杭州东站 到 凤起路 的矩形
SELECT * FROM hz_map WHERE location.envelope('[[120.219328,30.297086], [120.170389,30.268238]]');

-- 杭州东站 到 城站 的矩形
SELECT * FROM hz_map WHERE location.envelope('[[120.219328,30.297086], [120.187708,30.250083]]');

-- 凤起路 1公里范围内
SELECT * FROM hz_map WHERE location.circle('[120.170389,30.268238]', '1km');

-- 凤起路 2公里范围内
SELECT * FROM hz_map WHERE location.circle('[120.170389,30.268238]', '2km');