지리 경계 집계
지리 경계 집계 (Geobounds aggregation)
geo_bounds 집계는 geo_point 또는 geo_shape 객체의 집합을 감싸는 지리적 경계 상자(bounding box)를 계산하는 다중 값(multi-value) 집계예요. 경계 상자는 십진수로 인코딩된 위도-경도(lat-lon) 쌍으로 주어지는 사각형의 왼쪽 위와 오른쪽 아래 꼭짓점으로 반환돼요.
출처: 문서
본문
파라미터
geo_bounds 집계는 다음과 같은 파라미터를 받아요.
| 파라미터 | 필수/선택 | 데이터 타입 | 설명 |
|---|---|---|---|
field |
필수 | String | 지리 경계를 계산할 지오포인트(geopoints) 또는 지오셰이프(geoshapes)가 담긴 필드의 이름이에요. |
wrap_longitude |
선택 | Boolean | 경계 상자가 국제 날짜 변경선(international date line)을 겹칠 수 있게 할지 여부예요. 기본값은 true예요. |
예제
다음 예제는 e-커머스 샘플 데이터의 모든 주문에 대해 geoip.location의 geo_bounds를 반환해요(각 geoip.location은 지오포인트예요):
GET opensearch_dashboards_sample_data_ecommerce/_search
{
"size": 0,
"aggs": {
"geo": {
"geo_bounds": {
"field": "geoip.location"
}
}
}
}
예제 응답
다음 예제 응답에서 볼 수 있듯이, 집계는 geoip.location 필드의 모든 지오포인트를 포함하는 지리 경계를 반환해요:
{
"took": 16,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 4675,
"relation": "eq"
},
"max_score": null,
"hits": []
},
"aggregations": {
"geo": {
"bounds": {
"top_left": {
"lat": 52.49999997206032,
"lon": -118.20000001229346
},
"bottom_right": {
"lat": 4.599999985657632,
"lon": 55.299999956041574
}
}
}
}
}
지오셰이프 집계 (Aggregating geoshapes)
geo_bounds 집계를 지오셰이프에 대해 실행할 수 있어요.
지오셰이프 필드를 포함한 인덱스를 생성해 예제를 준비해 봐요:
PUT national_parks
{
"mappings": {
"properties": {
"location": {
"type": "geo_shape"
}
}
}
}
인덱스에 문서를 넣어요. GeoJSON 입력은 경도를 먼저 지정해요:
POST _bulk
{ "create": { "_index": "national_parks", "_id": "1" } }
{"name": "Yellowstone National Park", "location": {"type": "envelope","coordinates": [ [-111.15, 45.12], [-109.83, 44.12] ]}}
{ "create": { "_index": "national_parks", "_id": "2" } }
{ "name": "Yosemite National Park", "location": {"type": "envelope","coordinates": [ [-120.23, 38.16], [-119.05, 37.45] ]} }
{ "create": { "_index": "national_parks", "_id": "3" } }
{ "name": "Death Valley National Park", "location": {"type": "envelope","coordinates": [ [-117.34, 37.01], [-116.38, 36.25] ]} }
{ "create": { "_index": "national_parks", "_id": "4" } }
{ "name": "War In The Pacific National Historic Park Guam", "location": {"type": "point","coordinates": [144.72, 13.47]} }
location 필드에 대해 geo_bounds 집계를 실행해 봐요:
GET national_parks/_search
{
"size": 0,
"aggregations": {
"grouped": {
"geo_bounds": {
"field": "location",
"wrap_longitude": true
}
}
}
}
응답에는 location 필드의 모든 도형을 둘러싸는 가장 작은 지리 경계 상자가 담겨 있어요:
{
"took": 8,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 4,
"relation": "eq"
},
"max_score": null,
"hits": []
},
"aggregations": {
"grouped": {
"bounds": {
"top_left": {
"lat": 45.11999997776002,
"lon": 144.71999991685152
},
"bottom_right": {
"lat": 13.469999986700714,
"lon": -109.83000006526709
}
}
}
}
}
경도 감싸기 (Wrapping longitude)
선택 파라미터인 wrap_longitude를 true로 설정하면 경계 상자가 국제 날짜 변경선(180° 경선)을 겹칠 수 있고, 왼쪽 위 경도가 오른쪽 아래 경도보다 큰 bounds 객체가 반환돼요. wrap_longitude의 기본값은 true예요.
wrap_longitude를 false로 설정해 국립공원 지오셰이프에 대해 geo_bounds 집계를 다시 실행해 봐요:
GET national_parks/_search
{
"size": 0,
"aggregations": {
"grouped": {
"geo_bounds": {
"field": "location",
"wrap_longitude": false
}
}
}
}
새로 생성된 지리 경계가 날짜 변경선과 겹치지 않도록 더 넓은 영역을 감싸는 것을 확인할 수 있어요:
{
...
"aggregations": {
"grouped": {
"bounds": {
"top_left": {
"lat": 45.11999997776002,
"lon": -120.23000006563962
},
"bottom_right": {
"lat": 13.469999986700714,
"lon": 144.71999991685152
}
}
}
}
}
OpenSearch는 API를 통해서는 지오셰이프 집계를 지원하지만, OpenSearch Dashboards 시각화에서는 지원하지 않아요.