모든 인덱스는 두 개의 정보 단위를 가지고 있는데 바로 settings 과 mappings
인덱스를 처음 생성한 뒤 GET <인덱스명>
으로 조회하면 설정(settings) 그리고 매핑(mappings) 정보를 확인할 수 있음
$ curl -XPUT "<http://localhost:9200/my_index>"
$ curl -XGET "<http://localhost:9200/my_index>"
GET my_index/_settings
처럼 인덱스명 뒤에 _settings 또는 _mappings 를 추가해서 볼 수 있음PUT my_index
명령으로 인덱스만 생성하고 데이터는 입력하지 않았기 때문에 "mappings" : { }
정보는 아직 생성되지 않았음먼저 앞에서 여러 번 이미 언급을 했는데, 프라이머리 샤드 수와 리플리카는 다음과 같이 각각 number_of_shards, number_of_replicas 에서 설정
대부분의 설정들은 settings 아래의 index 아래 설정에 명시되는데 index 레벨은 생략하고 입력하여도 정상적으로 입력이 됨
JSON 설정값은 { } 내부에 써도 되고 마침표 .
를 이용해서 구조를 정의하는것도 가능하며, 다음 명령들은 모두 동일하게 동작
$ curl -XPUT "<http://localhost:9200/my_index>" -H 'Content-Type: application/json' -d '
{
"settings": {
"index": {
"number_of_shards": 3,
"number_of_replicas": 1
}
}
}
'
.
으로 하위 값 지정$ curl -XPUT "<http://localhost:9200/my_index>" -H 'Content-Type: application/json' -d '
{
"settings": {
"index.number_of_shards": 3,
"index.number_of_replicas": 1
}
}
'
$ curl -XPUT "<http://localhost:9200/my_index>" -H 'Content-Type: application/json' -d '
{
"settings": {
"number_of_shards": 3,
"number_of_replicas": 1
}
}
'
number_of_shards 설정은 인덱스를 처음 생성할 때 한번 지정하면 변경 불가
샤드 수를 바꾸려면 새로 인덱스를 정의하고 기존 인덱스의 데이터를 재색인 해야 함
hrink API또는 split API를 이용해서 샤드 수를 변경하는 방법이 존재하기는 하지만 인덱스를 close 해야 하고, 파일 재배치를 하는 작업을 하는 복잡한 과정이기에 기본적으로 샤드 수의 변경은 불가능하다 라고 인식하고 사용하는 것이 좋음
number_of_replicas 설정은 다이나믹하게 변경이 가능. 이미 선언된 my_index의 복제본 카피 개수를 1에서 2로 변경하려면 인덱스명 뒤에 _settings API로 접근해서 변경할 설정만 입력해서 변경이 가능합니다.
$ curl -XPUT "<http://localhost:9200/my_index/_settings>" -H 'Content-Type: application/json' -d '
{
"number_of_replicas": 2
}
'
$ curl -XGET "<http://localhost:9200/my_index/>"
or
$ curl -XGET "<http://localhost:9200/my_index/_settings>"
Elasticsearch 에서 세그먼트가 만들어지는 리프레시 타임을 설정하는 값인데 기본은 1초(1s)
refresh_interval 역시 number_of_replicas 마찬가지로 설정 변경이 가능한 다이나믹 설정이며 똑같이 settings 의 index 아래에 설정
다음은 처음 인덱스를 정의할 때 refresh_interval을 30초로 설정하는 명령
$ curl -XPUT "<http://localhost:9200/my_index>" -H 'Content-Type: application/json' -d '
{
"settings": {
"refresh_interval": "30s"
}
}
'
$ curl -XGET "<http://localhost:9200/my_index/_settings>"