본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

인덱스 리프레시 API (Refresh Index API)

원문 보기 위키 갱신

Refresh Index API는 하나 이상의 인덱스를 리프레시해서, 마지막 리프레시 이후 해당 인덱스에서 수행된 모든 연산을 검색에 사용할 수 있게 해요. 문서를 인덱싱하면 먼저 translog에 기록되고 메모리 내 버퍼에 추가됩니다. 리프레시 연산이 이 메모리 내 구조를 디스크의 검색 가능한 세그먼트로 변환하기 전까지 문서는 검색할 수 없어요. 데이터 스트림의 경우 Refresh Index API는 스트림의 backing index를 리프레시합니다.

OpenSearch에서 리프레시 연산이 어떻게 동작하는지에 대한 개념적 개요는 Refresh 문서를 참고하세요.

출처: OpenSearch 문서

본문

Refresh interval

index.refresh_interval 설정은 인덱스가 자동으로 얼마나 자주 리프레시되는지 제어합니다. OpenSearch의 리프레시 동작은 index.refresh_interval이 설정되어 있는지에 따라 달라집니다.

  • 설정되어 있으면 인덱스는 index.refresh_interval 설정(초 단위)에 따라 리프레시됩니다. index.refresh_interval 설정에 대한 자세한 내용은 Dynamic index settings 문서를 참고하세요.
  • 설정되어 있지 않으면 샤드가 index.search.idle.after 설정(초 단위)에 지정된 시간 이상 검색 요청을 받지 못할 때까지 매초 리프레시됩니다. 기본값은 30초입니다. 샤드가 유휴 상태가 되면 다음 검색 요청이나 Refresh Index API 요청이 올 때까지 인덱스는 리프레시되지 않습니다. 유휴 샤드의 첫 번째 검색 요청은 리프레시 연산이 완료될 때까지 기다릴 거예요.

Refresh Index API를 사용하려면 리프레시하려는 인덱스에 쓰기 권한이 있어야 합니다.

Refresh request behavior

Refresh Index API 호출은 동기식입니다. 대상이 되는 모든 샤드가 리프레시된 후에만 응답이 반환됩니다.

Best practices

리프레시 연산은 리소스를 많이 소모하고 클러스터 성능에 영향을 줄 수 있어요. 최적의 클러스터 성능을 보장하려면 다음 모범 사례를 권장합니다.

  • 자동 리프레시에 의존하세요. 가능하면 명시적 리프레시를 수행하는 대신 OpenSearch의 주기적 리프레시(index.refresh_interval로 제어)를 기다리세요.
  • 인덱싱 워크플로우에는 refresh=wait_for를 사용하세요. 애플리케이션이 문서를 인덱싱한 뒤 즉시 검색한다면, Refresh API를 호출하는 대신 인덱싱 연산에 refresh=wait_for 쿼리 파라미터를 사용하세요. 이 옵션은 즉시 리프레시를 강제하지 않으면서 인덱싱 연산이 주기적 리프레시를 기다린 후 반환되도록 보장합니다. 자세한 내용은 The refresh query parameter 문서를 참고하세요.
  • 프로덕션에서 refresh=true는 피하세요. index, update, delete 연산에서 refresh=true를 사용하면 즉시 리프레시를 강제하고 나중에 병합해야 하는 비효율적인 인덱스 구조(작은 세그먼트)를 만들어 인덱싱과 검색 성능 모두에 영향을 줍니다.

Endpoints

POST /_refresh
GET /_refresh
POST /{index}/_refresh
GET /{index}/_refresh

Path parameters

다음 표는 사용 가능한 경로 파라미터를 보여줘요. 모든 경로 파라미터는 선택사항이에요.

| Parameter | Data type | Description | | index | String | A comma-separated list of index names to be refreshed. Wildcards are accepted. |

Query parameters

다음 표는 사용 가능한 쿼리 파라미터를 보여줘요. 모든 쿼리 파라미터는 선택사항이에요.

| Parameter | Data type | Description | | ignore_unavailable | Boolean | When false, the request returns an error when it targets a missing or closed index. Default is false. | | allow_no_indices | Boolean | When false, the Refresh Index API returns an error when a wildcard expression, index alias, or _all targets only closed or missing indexes, even when the request is made against open indexes. Default is true. | | expand_wildcards | String | The type of index that the wildcard patterns can match. If the request targets data streams, this argument determines whether the wildcard expressions match any hidden data streams. Supports comma-separated values, such as open,hidden. Valid values are all, open, closed, hidden, and none. |

Example request: Refreshing several data streams or indexes

다음 예시 요청은 my-index-A와 my-index-B라는 두 인덱스를 리프레시해요.

REST Python

POST /my-index-A,my-index-B/_refresh

Copy Copy as cURL

response = client.indices.refresh(
index = "my-index-A,my-index-B"
)

Copy

Example request: Refreshing all data streams and indexes

다음 요청은 클러스터의 모든 데이터 스트림과 인덱스를 리프레시해요.

POST /_refresh

copy

Example request: Refreshing using the GET method

GET 메서드를 사용해 인덱스를 리프레시할 수도 있어요. 다음 예시는 GET을 사용해 특정 인덱스를 리프레시합니다.

GET /my-index/_refresh

copy

GET 메서드는 POST 메서드와 완전히 동일하게 동작하며, POST 요청이 제한된 환경이나 읽기류 연산에 GET을 선호하는 환경에서 유용해요.

The refresh query parameter

Index, Update, Delete, Bulk API 같은 문서 API는 요청으로 인한 변경 사항을 언제 검색에 노출할지 제어하는 refresh 쿼리 파라미터를 지원해요. 이 파라미터는 Refresh Index API를 명시적으로 호출하는 것의 대안을 제공합니다.

refresh 파라미터에 대한 자세한 내용은 Index Document API, Update Document API, Delete Document API, Bulk API 문서를 참고하세요.

Required permissions

Security 플러그인을 사용한다면 적절한 권한(indices:admin/refresh 및 indices:admin/refresh*)을 가지고 있는지 확인하세요.

더 알아보기 (Learn more)