Elasticsearch 살펴보기 5탄 - Index API

bradley·2022년 6월 14일
1

ELK

목록 보기
7/8

Index API는 setting, aliases, mappings, index templates같은 index의 모든 측면을 관리한다.

Index 생성

이 API는 index를 생성한다. index는 JSON Object를 어떤 index에라도 통과시킬 때 자동으로 생성된다. 또는 JSON Object를 pass 시키기 전에 만들 수 있다. index를 만드려면 settings, mappings, alias를 포함한 PUT request 또는 body가 없는 간단한 request를 보내야 한다.

Command Example

PUT colleges

정상 출력

{
  "acknowledged" : true,
  "shards_acknowledged" : true,
  "index" : "colleges"
}

Index 삭제

특정 index 이름을 포함한 delete request를 보낸다. _all 또는 *을 이용해 다중 index를 삭제할 수도 있다.

Command Example

DELETE /colleges

정상 출력

{
  "acknowledged" : true
}

index 정보 얻기

한 개 또는 그 이상의 index에 get request를 보낸다. 그러면 index에 대한 정보들을 return한다. _all 또는 *를 이용하여 다중 index의 정보를 얻을 수 있다.

Command Example

GET colleges

정상 출력

{
  "colleges" : {
    "aliases" : { },
    "mappings" : { },
    "settings" : {
      "index" : {
        "creation_date" : "1655186365541",
        "number_of_shards" : "1",
        "number_of_replicas" : "1",
        "uuid" : "rklEs1hqTv6JhaKDll-oDA",
        "version" : {
          "created" : "7060299"
        },
        "provided_name" : "colleges"
      }
    }
  }
}

index 존재 여부 확인

index가 존재하는지 여부를 확인한다. 존재하면 HTTP response는 200, 존재하지 않으면 404를 return한다.

Command Example

HEAD colleges

정상 출력

200 - OK
404 - Not Found

index 설정값 얻기

URL 끝에 _settings 키워드를 추가하면 index settings 값을 얻을 수 있다.

Command Example

GET colleges/_settings

정상 출력

{
  "colleges" : {
    "settings" : {
      "index" : {
        "creation_date" : "1655186601043",
        "number_of_shards" : "1",
        "number_of_replicas" : "1",
        "uuid" : "l_iw7081TJ-GtCNXbfxXxw",
        "version" : {
          "created" : "7060299"
        },
        "provided_name" : "colleges"
      }
    }
  }
}

index 통계

특정 index에 대한 통계치를 추출한다. URL의 끝에 _stats를 통해 얻을 수 있다.

Command Example

GET colleges/_stats

정상 출력

{
  "_shards" : {
    "total" : 2,
    "successful" : 1,
    "failed" : 0
  },
  "_all" : {
    "primaries" : {
      "docs" : {
        "count" : 0,
        "deleted" : 0
      },
      "store" : {
        "size_in_bytes" : 230
      },
      "indexing" : {
        "index_total" : 0,
        "index_time_in_millis" : 0,
        "index_current" : 0,
        "index_failed" : 0,
        "delete_total" : 0,
        "delete_time_in_millis" : 0,
        "delete_current" : 0,
        "noop_update_total" : 0,
        "is_throttled" : false,
        "throttle_time_in_millis" : 0
      },
      ...

Flush

index의 flush 프로세스는 현재 트랜잭션 로그에서만 유지되는 모든 데이터가 Apache Lucene 안에서도 영구적으로 유지되도록 한다. 이렇게 하면 index된 Lucene이 열린 후 트랜잭션 로그에서 데이터를 다시 indexing할 필요가 없으므로 복구 시간이 단축된다.

Command Example

POST colleges/_flusth

정상 출력

{
  "_shards" : {
    "total" : 2,
    "successful" : 1,
    "failed" : 0
  }
}
profile
데이터 엔지니어링에 관심이 많은 홀로 삽질하는 느림보

0개의 댓글