지리 중심점 집계

지리 중심점 집계 (Geocentroid aggregation)

geo_centroid 집계는 geo_point 값들의 집합에 대한 지리적 중심점 또는 초점을 계산해요. 중심점 위치를 위도-경도 쌍으로 반환해 줘요.

출처: 문서

본문

파라미터

geo_centroid 집계는 다음과 같은 파라미터를 받아요.

파라미터 필수/선택 데이터 타입 설명
field 필수 String 지리 중심점을 계산할 지오포인트(geopoints)가 담긴 필드의 이름이에요.

예제

다음 예제는 e-커머스 샘플 데이터의 모든 주문에 대해 geoip.location의 geo_centroid를 반환해요. 각 geoip.location은 지오포인트예요:

GET /opensearch_dashboards_sample_data_ecommerce/_search
{
  "size": 0,
  "aggs": {
    "centroid": {
      "geo_centroid": {
        "field": "geoip.location"
      }
    }
  }
}

예제 응답

응답에는 인덱스된 모든 데이터 포인트의 중심점 위치를 나타내는 lat과 lon 속성을 가진 centroid 객체가 포함돼요:

{
  "took": 35,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": {
      "value": 4675,
      "relation": "eq"
    },
    "max_score": null,
    "hits": []
  },
  "aggregations": {
    "centroid": {
      "location": {
        "lat": 35.54990372113027,
        "lon": -9.079764742533712
      },
      "count": 4675
    }
  }
}

중심점 위치는 모로코 북쪽 대서양에 있어요. 데이터베이스에 있는 주문들의 지리적 분포가 넓다는 점을 고려하면, 이 값은 그다지 의미가 있지 않아요.

다른 집계 아래에 중첩하기 (Nesting under other aggregations)

geo_centroid 집계를 버킷 집계 안에 중첩해 데이터의 하위 집합에 대한 중심점을 계산할 수 있어요.

예제: terms 집계 아래에 중첩하기

geo_centroid 집계를 문자열 필드의 terms 버킷 아래에 중첩할 수 있어요.

각 대륙의 주문에 대한 geoip의 중심점 위치를 찾으려면 geoip.continent_name 필드 안에 중심점 하위 집계(sub-aggregation)를 구성해 봐요:

GET /opensearch_dashboards_sample_data_ecommerce/_search
{
  "size": 0,
  "aggs": {
    "continents": {
      "terms": {
        "field": "geoip.continent_name"
      },
      "aggs": {
        "centroid": {
          "geo_centroid": {
            "field": "geoip.location"
          }
        }
      }
    }
  }
}

이 요청은 각 대륙 버킷에 대한 중심점 위치를 반환해요:

{
  "took": 34,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": {
      "value": 4675,
      "relation": "eq"
    },
    "max_score": null,
    "hits": []
  },
  "aggregations": {
    "continents": {
      "doc_count_error_upper_bound": 0,
      "sum_other_doc_count": 0,
      "buckets": [
        {
          "key": "Asia",
          "doc_count": 1220,
          "centroid": {
            "location": {
              "lat": 28.023606536509163,
              "lon": 47.83377046025068
            },
            "count": 1220
          }
        },
        {
          "key": "North America",
          "doc_count": 1206,
          "centroid": {
            "location": {
              "lat": 39.06542286878007,
              "lon": -85.36152573149485
            },
            "count": 1206
          }
        },
        {
          "key": "Europe",
          "doc_count": 1172,
          "centroid": {
            "location": {
              "lat": 48.125767892293325,
              "lon": 2.7529009746915243
            },
            "count": 1172
          }
        },
        {
          "key": "Africa",
          "doc_count": 899,
          "centroid": {
            "location": {
              "lat": 30.780756367941297,
              "lon": 13.464182392125318
            },
            "count": 899
          }
        },
        {
          "key": "South America",
          "doc_count": 178,
          "centroid": {
            "location": {
              "lat": 4.599999985657632,
              "lon": -74.10000007599592
            },
            "count": 178
          }
        }
      ]
    }
  }
}

더 알아보기 (Learn more)