0Pricing
Elasticsearch & Full Text Search Systems · 강의

지리 공간 검색 기능

위치 기반 검색, 근접 질의, 지리 공간 집계를 수행하도록 지리 좌표 및 지리 도형 매핑을 구현합니다.

지리 공간 검색 기능은(는) CoddyKit의 무료 Elasticsearch & Full Text Search Systems 강의입니다. 이것은 4개 중 1번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 Elasticsearch & Full Text Search Systems 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. Elasticsearch & Full Text Search Systems 강의에는 총 4개의 강의가 포함되어 있습니다.

이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.

Location-Aware Search

Welcome to Geospatial Search! Many modern applications rely on location data, from finding nearby restaurants to tracking delivery vehicles.

Elasticsearch provides powerful features to index, search, and analyze geographic information efficiently.

The `geo_point` Field

The most common way to store a single geographical location in Elasticsearch is using the geo_point data type.

It represents a specific point on Earth using its latitude and longitude coordinates.

  • Latitude: North-South position (e.g., 48.8584)
  • Longitude: East-West position (e.g., 2.2945)

Mapping `geo_point` Data

Before indexing documents with location data, you need to define a geo_point field in your index mapping. This tells Elasticsearch how to interpret the coordinates.

Try setting up an index named places with a location field of type geo_point:

curl -X PUT "localhost:9200/places?pretty" -H 'Content-Type: application/json' -d'
{
  "mappings": {
    "properties": {
      "location": {
        "type": "geo_point"
      },
      "name": {
        "type": "text"
      }
    }
  }
}'

Adding Geo-Tagged Documents

Now that our places index is mapped, we can index documents containing geo_point data. The location field can accept an object with lat and lon properties.

Index the Eiffel Tower's location:

curl -X PUT "localhost:9200/places/_doc/1?pretty" -H 'Content-Type: application/json' -d'
{
  "name": "Eiffel Tower",
  "location": {
    "lat": 48.8584,
    "lon": 2.2945
  }
}'

Searching by Distance: `geo_distance`

One of the most common geospatial queries is finding documents within a certain radius of a central point. This is achieved using the geo_distance query.

You specify a distance and the reference point, and Elasticsearch returns all matching documents.

`geo_distance` Query Example

Let's find all places within 5 kilometers of the Eiffel Tower's coordinates. This query is perfect for 'find restaurants near me' features.

Run this query:

curl -X GET "localhost:9200/places/_search?pretty" -H 'Content-Type: application/json' -d'
{
  "query": {
    "geo_distance": {
      "distance": "5km",
      "location": {
        "lat": 48.8584,
        "lon": 2.2945
      }
    }
  }
}'

Bounding Box Search (`geo_bounding_box`)

Another useful query is geo_bounding_box, which allows you to find all documents whose geo_point falls within a specified rectangular area.

You define the box by providing its top_left and bottom_right coordinates.

`geo_bounding_box` Query Example

Imagine you have a map view and only want to show results within the current screen. A geo_bounding_box query is ideal for this scenario.

Here's an example searching within a small area around Paris:

curl -X GET "localhost:9200/places/_search?pretty" -H 'Content-Type: application/json' -d'
{
  "query": {
    "geo_bounding_box": {
      "location": {
        "top_left": {
          "lat": 49,
          "lon": 2
        },
        "bottom_right": {
          "lat": 48,
          "lon": 3
        }
      }
    }
  }
}'

Beyond Points: `geo_shape`

While geo_point is great for single locations, what if you need to represent complex geometries like a park boundary, a river, or a country's outline?

For this, Elasticsearch offers the geo_shape data type, which supports various GeoJSON shapes (polygons, lines, multi-points, etc.).

`geo_shape` Mapping & Indexing

To use geo_shape, you first map the field as geo_shape. Then, you can index documents with complex geometries, typically in GeoJSON format. Here's how to map and index a simple polygon representing a district:

curl -X PUT "localhost:9200/regions?pretty" -H 'Content-Type: application/json' -d'
{
  "mappings": {
    "properties": {
      "area": {
        "type": "geo_shape"
      },
      "name": {
        "type": "keyword"
      }
    }
  }
}'

curl -X PUT "localhost:9200/regions/_doc/1?pretty" -H 'Content-Type: application/json' -d'
{
  "name": "Paris District",
  "area": {
    "type": "polygon",
    "coordinates": [
      [
        [2.2, 48.8],
        [2.3, 48.8],
        [2.3, 48.9],
        [2.2, 48.9],
        [2.2, 48.8]
      ]
    ]
  }
}'

Geo Query Challenge

You want to find all restaurants located within the boundaries of a specific park. The park's boundaries are complex and not a simple rectangle.

Geospatial Search Recap

You've explored Elasticsearch's powerful geospatial capabilities!

  • We learned about the geo_point type for single locations (latitude, longitude).
  • We used geo_distance for proximity searches and geo_bounding_box for rectangular area searches.
  • We also introduced the advanced geo_shape type for complex geometries like polygons.

These tools are essential for building sophisticated location-aware applications.

자주 묻는 질문

“지리 공간 검색 기능” 강의는 무료인가요?

네 — “지리 공간 검색 기능” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 Elasticsearch & Full Text Search Systems 강의 전체를 잠금 해제할 수 있습니다. Elasticsearch & Full Text Search Systems 강의에는 총 4개의 강의가 포함되어 있습니다.

“지리 공간 검색 기능”에서 뭘 배우나요?

위치 기반 검색, 근접 질의, 지리 공간 집계를 수행하도록 지리 좌표 및 지리 도형 매핑을 구현합니다. 브라우저에서 직접 실행하는 실습 코드로 Elasticsearch & Full Text Search Systems을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.

Elasticsearch & Full Text Search Systems을(를) 시작하는 데 경험이 필요한가요?

사전 경험은 필요하지 않습니다. CoddyKit의 Elasticsearch & Full Text Search Systems은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 1번째 강의입니다.

“지리 공간 검색 기능” 강의는 얼마나 걸리나요?

대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.

이 Elasticsearch & Full Text Search Systems 강의에서 코드를 작성하고 실행할 수 있나요?

네. 모든 Elasticsearch & Full Text Search Systems 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.

이 강의의 모든 강의

  1. 지리 공간 검색 기능
  2. 시계열 데이터 관리
  3. 운영 환경 배포 전략
  4. 인덱스 수명 주기 관리
← Elasticsearch & Full Text Search Systems(으)로 돌아가기