모든 인덱스는 두 개의 메타 정보 단위를 가진다. settings와 mappings임. 인덱스를 처음 생성한 뒤 GET <인덱스>으로 조회하면 설정(settings)그리고 매핑(mappings)정보를 확인할 수 있다.
{
"my_index": {
"aliases": {},
"mappings": {},
"settings": {
"index": {
"routing": {
"allocation": {
"include": {
"_tier_preference": "data_content"
}
}
},
"number_of_shards": "1",
"provided_name": "my_index",
"creation_date": "1751288751916",
"number_of_replicas": "1",
"uuid": "Q8sa2FqvSGivHT2GZ1hZAg",
"version": {
"created": "9009000"
}
}
}
}
}
settings 또는 mappings정보만 따로 볼 수 도 있다.
my_index/_settings
를 뒤에 붙여주면 됨.
{
"my_index": {
"mappings": {}
}
}
처음 인덱스를 정의하면 몇가지 정보가 자동으로 생성이 된다. 샤드 수나 복제본 수같은 정보는 settings아래 설정됨.
"settings": {
"index": {
"routing": {
"allocation": {
"include": {
"_tier_preference": "data_content"
}
}
},
"number_of_shards": "1",
"provided_name": "my_index",
"creation_date": "1751288751916",
"number_of_replicas": "1",
"uuid": "Q8sa2FqvSGivHT2GZ1hZAg",
"version": {
"created": "9009000"
}
}
}
💡 샤드 수는 7.0부터는 디폴트 1개로 설정되었다.
프라이머리 샤드 수와 레플리카는 number_of_shards
, number_of_replicas
에서 설정한다. 대부분의 설정은 settings.index 아래 설정에 명시되는데, index레벨은 생략하고 입력해도 정상적으로 입력됨. 아래는 모두 동일한 설정이다.
PUT my_index
{
"settings": {
"index": {
"number_of_shards": 3,
"number_of_replicas": 1
}
}
}
PUT my_index
{
"settings": {
"index.number_of_shards": 3,
"index.number_of_replicas": 1
}
}
PUT my_index
{
"settings": {
"number_of_shards": 3,
"number_of_replicas": 1
}
}
여기서 number_of_shards
설정은 인덱스를 처음 생성할때 한번 지정하면 바꿀 수 없다. 샤드 수를 바꾸려면 새로 인덱스를 정의하고 기존 인덱스 데이터를 재색인해야 한다.
shrink API 또는 split API를 이용할 수 있지만, 복잡하기 때문에 기본적으로는 안된다고 생각하고 접근하는게 좋다.