CAT API
CAT API
OpenSearch 클러스터의 핵심 통계를 표 형태로 쉽게 확인하고 싶을 때가 있죠? 그럴 때 사용하는 게 바로 CAT(compact and aligned text) API예요. 이 API는 기존의 JSON 대신 사람이 읽기 쉬운 순수 텍스트를 돌려주는 인터페이스예요.
CAT API를 쓰면 이런 질문에 바로 답할 수 있어요. 어떤 노드가 elected cluster manager인지, 클러스터 상태는 어떤지, 각 인덱스에 문서가 몇 개인지 같은 것들이요.
출처: 문서
본문
1.0에서 도입
예시
CAT API에서 사용 가능한 작업을 보려면 다음 명령을 사용해요.
GET /_cat
응답은 ASCII 고양이(=^.^=)와 작업 목록으로 나와요.
=^.^=
/_cat/allocation
/_cat/segment_replication
/_cat/segment_replication/{index}
/_cat/shards
/_cat/shards/{index}
/_cat/cluster_manager
/_cat/nodes
/_cat/tasks
/_cat/indices
/_cat/indices/{index}
/_cat/segments
/_cat/segments/{index}
/_cat/count
/_cat/count/{index}
/_cat/recovery
/_cat/recovery/{index}
/_cat/health
/_cat/pending_tasks
/_cat/aliases
/_cat/aliases/{alias}
/_cat/thread_pool
/_cat/thread_pool/{thread_pools}
/_cat/plugins
/_cat/fielddata
/_cat/fielddata/{fields}
/_cat/nodeattrs
/_cat/repositories
/_cat/snapshots/{repository}
/_cat/templates
/_cat/pit_segments
/_cat/pit_segments/{pit_id}
선택적 쿼리 파라미터
루트 _cat API 자체는 파라미터를 받지 않지만, /_cat/nodes 같은 개별 API는 다음 쿼리 파라미터를 지원해요.
| Parameter | Description |
|---|---|
| v | 열에 헤더를 추가해 자세한(verbose) 출력을 제공해요. 각 열을 정렬하는 데 도움이 되는 일부 서식도 추가하고요. 이 섹션의 모든 예시에는 v 파라미터가 포함돼 있어요. |
| help | 특정 작업에 사용할 수 있는 기본 및 기타 헤더를 나열해요. |
| h | 출력을 특정 헤더로 제한해요. |
| format | 결과를 반환할 형식이에요. 유효한 값은 json, yaml, cbor, smile이에요. |
| s | 지정한 열 기준으로 출력을 정렬해요. |
쿼리 파라미터 사용 예시
모든 CAT 작업에 쿼리 파라미터를 지정하면 더 구체적인 결과를 얻을 수 있어요.
자세한 출력 얻기
응답에 모든 열 헤더가 포함된 자세한 출력을 얻으려면 v 쿼리 파라미터를 사용해요.
GET /_cat/aliases?v
응답은 응답의 각 열 이름 같은 더 많은 세부 정보를 제공해요.
alias index filter routing.index routing.search is_write_index
.kibana .kibana_1 - - - -
sample-alias1 sample-index-1 - - - -
verbose 파라미터 v 없이 요청하면 응답은 단순히 alias 이름만 반환해요.
.kibana .kibana_1 - - - -
sample-alias1 sample-index-1 - - - -
사용 가능한 모든 헤더 가져오기
사용 가능한 모든 헤더를 보려면 help 파라미터를 사용해요.
GET _cat/{operation_name}?help
예를 들어 CAT aliases 작업의 사용 가능한 헤더를 보려면 다음 요청을 보내요.
GET /_cat/aliases?help
응답에 사용 가능한 헤더가 포함돼 있어요.
alias | a | alias name
index | i,idx | index alias points to
filter | f,fi | filter
routing.index | ri,routingIndex | index routing
routing.search | rs,routingSearch | search routing
is_write_index | w,isWriteIndex | write index
헤더 부분집합 가져오기
출력을 헤더 부분집합으로 제한하려면 h 파라미터를 사용해요.
GET _cat/{operation_name}?h={header_name_1},{header_name_2}&v
예를 들어 aliases를 alias 이름과 인덱스로만 제한하려면 다음 요청을 보내요.
GET /_cat/aliases?h=alias,index
응답에 요청한 정보가 포함돼 있어요.
.kibana .kibana_1
sample-alias1 sample-index-1
일반적으로 어떤 작업이든 help 파라미터로 사용 가능한 헤더를 확인한 다음, h 파라미터로 필요한 헤더만 출력하도록 제한할 수 있어요.
헤더 기준 정렬
헤더 기준으로 출력을 정렬하려면 s 파라미터를 사용해요.
GET _cat/{operation_name}?s={header_name_1},{header_name_2}
예를 들어 aliases를 alias 다음 인덱스 순으로 정렬하려면 다음 요청을 보내요.
GET /_cat/aliases?s=i,a
응답에 요청한 정보가 포함돼 있어요.
sample-alias2 sample-index-1
sample-alias1 sample-index-2
JSON 형식으로 데이터 검색하기
기본적으로 CAT API는 데이터를 text/plain 형식으로 반환해요.
JSON 형식으로 데이터를 가져오려면 format=json 파라미터를 사용해요.
GET _cat/{operation_name}?format=json
예를 들어 aliases를 JSON 형식으로 가져오려면 다음 요청을 보내요.
GET /_cat/aliases?format=json
응답에 JSON 형식의 데이터가 포함돼 있어요.
[
{"alias":".kibana","index":".kibana_1","filter":"-","routing.index":"-","routing.search":"-","is_write_index":"-"},
{"alias":"sample-alias-1","index":"sample-index-1","filter":"-","routing.index":"-","routing.search":"-","is_write_index":"-"}
]
그 밖에 지원되는 형식은 YAML, CBOR, Smile이에요.
CAT API 작업
다음 CAT API 작업을 사용할 수 있어요.
클러스터 및 노드 정보
- CAT aliases
- CAT allocation
- CAT cluster manager
- CAT health
- CAT nodes
- CAT node attributes
- CAT pending tasks
- CAT plugins
- CAT repositories
- CAT tasks
- CAT templates
- CAT thread pool
인덱스 및 문서 정보
- CAT count
- CAT field data
- CAT indices
- CAT PIT segments
- CAT recovery
- CAT segment replication
- CAT segments
- CAT shards
스냅샷 정보
- CAT snapshots
보안
Security 플러그인을 사용한다면 적절한 권한이 있는지 확인해야 해요.
더 알아보기 (Learn more)
- CAT API의 각 작업 페이지에서 파라미터와 예시를 확인해 보세요.