List API
List API
2.18에서 도입
List API는 인덱스와 샤드에 대한 통계를 페이지 단위(paginated)로 가져와요. 인덱스가 많은 응답을 처리해야 할 때 이 작업을 훨씬 간편하게 만들어 줘요.
List API는 두 가지 작업을 지원해요.
- List indices: 인덱스 목록을 조회해요.
- List shards: 샤드 목록을 조회해요.
출처: 문서
본문
공통 쿼리 매개변수 (Shared query parameters)
모든 List API 작업은 다음 선택적 쿼리 매개변수를 지원해요.
| 매개변수 | 설명 |
|---|---|
v |
열에 헤더를 추가해서 자세한(verbose) 출력을 제공해요. 각 열을 정렬하기 위한 서식도 더해줘요. 이 섹션의 모든 예시에는 v 매개변수가 포함돼 있어요. |
help |
주어진 작업에 사용할 수 있는 기본 및 기타 헤더를 나열해요. |
h |
출력을 특정 헤더로 제한해요. |
format |
결과를 반환할 형식이에요. 유효한 값은 json, yaml, cbor, smile이에요. |
s |
지정한 열 기준으로 출력을 정렬해요. |
예시 (Examples)
다음 예시는 선택적 쿼리 매개변수로 모든 List API 응답을 원하는 대로 바꾸는 방법을 보여줘요.
자세한 출력 얻기 (Get verbose output)
응답에 모든 열 머리글을 포함한 자세한 출력으로 인덱스와 그 통계를 조회하려면 v 쿼리 매개변수를 사용해요.
요청
GET /_list/indices?v
Python 클라이언트로는 이렇게 호출해요:
response = client.list.indices(
params = { "v": "true" }
)
응답
health status index uuid pri rep docs.count docs.deleted
green open .kibana_1 - - - -
yellow open sample-index-1 - - - -
next_token null
사용 가능한 전체 헤더 보기 (Get all available headers)
사용 가능한 모든 헤더를 보려면 help 매개변수를 다음 구문으로 사용해요:
GET _list/{operation_name}?help
다음 예시는 list indices 작업의 사용 가능한 모든 헤더를 반환해요.
요청
GET /_list/indices?help
Python 클라이언트로는 이렇게 호출해요:
response = client.list.indices(
params = { "help": "true" }
)
응답
다음 예시는 인덱스와 건강 상태를 표로 보여줘요.
health | h | current health status
status | s | open/close status
index | i,idx | index name
uuid | id,uuid | index uuid
pri | p,shards.primary,shardsPrimary | number of primary shards
rep | r,shards.replica,shardsReplica | number of replica shards
docs.count | dc,docsCount | available docs
헤더 일부만 가져오기 (Get a subset of headers)
출력을 일부 헤더로 제한하려면 h 매개변수를 다음 구문으로 사용해요:
GET _list/{operation_name}?h={header_name_1},{header_name_2}&v
어떤 작업이든 help 매개변수로 사용 가능한 헤더를 확인한 뒤 h 매개변수로 출력을 일부 헤더로 제한할 수 있어요.
요청
다음 예시는 응답의 인덱스를 인덱스 이름과 건강 상태 헤더로만 제한해요.
GET /_list/indices?h=health,index
Python 클라이언트로는 이렇게 호출해요:
response = client.list.indices(
params = { "h": "health,index" }
)
응답
green .kibana_1
yellow sample-index-1
next_token null
헤더 기준 정렬 (Sort by a header)
단일 페이지의 출력을 헤더 기준으로 정렬하려면 s 매개변수를 다음 구문으로 사용해요:
GET _list/{operation_name}?s={header_name_1},{header_name_2}
요청
다음 예시는 인덱스를 인덱스 이름 기준으로 정렬해요.
GET /_list/indices?s=h,i
Python 클라이언트로는 이렇게 호출해요:
response = client.list.indices(
params = { "s": "h,i" }
)
응답
green sample-index-2
yellow sample-index-1
next_token null
JSON 형식으로 데이터 가져오기 (Retrieve data in JSON format)
기본적으로 List API는 text/plain 형식으로 데이터를 반환해요. 그 외 지원되는 형식은 YAML, CBOR, Smile이에요.
데이터를 JSON 형식으로 가져오려면 format=json 매개변수를 사용해요.
Security 플러그인을 사용한다면 적절한 권한이 있는지 확인해야 해요.
요청
GET /_list/indices?format=json
Python 클라이언트로는 이렇게 호출해요:
response = client.list.indices(
params = { "format": "json" }
)
응답
응답에는 JSON 형식의 데이터가 들어 있어요:
{
"next_token": null,
"indices": [
{
"health": "green",
"status": "-",
"index": ".kibana_1",
"uuid": "-",
"pri": "-",
"rep": "-",
"docs.count": "-",
"docs.deleted": "-",
"store.size": "-",
"pri.store.size": "-"
},
{
"health": "yellow",
"status": "-",
"index": "sample-index-1",
"uuid": "-",
"pri": "-",
"rep": "-",
"docs.count": "-",
"docs.deleted": "-",
"store.size": "-",
"pri.store.size": "-"
}
]
}