メインコンテンツまでスキップ

6. Elasticsearch에서 indices가 뭐야?

Elasticsearch에서 indices(색인)는 데이터를 저장하고 검색하기 위한 논리적인 컨테이너입니다. 각각의 인덱스는 유사한 유형의 문서들을 그룹화하는 데 사용됩니다.

인덱스는 Elasticsearch에서 데이터를 구성하는 주요 단위이며, 여러 개의 문서(Document)를 포함합니다. 각 문서는 JSON 형식으로 표현되며, 인덱스 내에서 고유한 ID로 식별됩니다.

인덱스는 데이터를 저장하고 검색, 분석, 집계하는 데 사용됩니다. Elasticsearch는 인덱스를 활용하여 데이터를 효율적으로 색인(indexing)하고 검색(search)할 수 있습니다. 인덱스는 일반적으로 관련된 데이터를 논리적으로 그룹화하고 효율적인 검색 및 집계 작업을 수행하기 위해 사용됩니다.

인덱스는 Elasticsearch에서 다양한 설정 및 매핑(mapping)을 가질 수 있습니다. 설정은 인덱스의 동작과 구성을 정의하는데 사용되며, 매핑은 인덱스 내 문서의 구조와 필드 유형을 정의합니다.

예를 들어, 온라인 상점에서 제품 데이터를 Elasticsearch에 저장한다고 가정해보면, "products"라는 이름의 인덱스를 생성할 수 있습니다. 해당 인덱스에는 제품에 관련된 문서들이 포함될 것이며, 각 문서는 제품의 속성과 정보를 JSON 형식으로 가지고 있습니다. 이렇게 생성된 "products" 인덱스를 사용하여 제품 검색, 필터링, 집계 등 다양한 작업을 수행할 수 있습니다.

인덱스는 Elasticsearch에서 데이터 구조화와 유연한 검색을 가능하게 하는 핵심 개념 중 하나이며, 데이터의 저장과 조회를 위한 중요한 요소입니다.

indices의 집합체가 index이다. 라고 생각하면 된다.

클러스터 확인

curl "http://localhost:9200/_cluster/state?pretty"
혹은 get 메서드로 날려본다

{
"cluster_name" : "Test Cluster",
"compressed_size_in_bytes" : 579,
"version" : 8,
"state_uuid" : "mrE5raXOQO2SVA8AROJqwQ",
"master_node" : "25457162-c5ef-44fa-a46b-a96434aae319",
"blocks" : { },
"nodes" : {
"25457162-c5ef-44fa-a46b-a96434aae319" : {
"name" : "172.17.0.2",
"status" : "ALIVE",
"ephemeral_id" : "25457162-c5ef-44fa-a46b-a96434aae319",
"transport_address" : "172.17.0.2:9300",
"attributes" : {
"rack" : "r1",
"dc" : "DC1"
}
}
},
"metadata" : {
"version" : 1,
"cluster_uuid" : "25457162-c5ef-44fa-a46b-a96434aae319",
"templates" : { },
"indices" : {
"test" : {
"state" : "open",
"settings" : {
"index" : {
"creation_date" : "1553512833429",
"number_of_shards" : "1",
"number_of_replicas" : "0",
"uuid" : "BOolxI89SqmrcbK7KM4sIA",
"version" : {
"created" : "6020399"
},
"provided_name" : "test"
}
},
"mappings" : {
"docs" : {
"properties" : {
"uid" : {
"cql_partition_key" : true,
"cql_primary_key_order" : 0,
"type" : "integer",
"cql_collection" : "singleton"
},
"login" : {
"type" : "keyword",
"cql_collection" : "singleton"
},
"username" : {
"cql_udt_name" : "user_type",
"type" : "nested",
"properties" : {
"last" : {
"type" : "keyword",
"cql_collection" : "singleton"
},
"first" : {
"type" : "keyword",
"cql_collection" : "singleton"
}
},
"cql_collection" : "singleton"
}
}
}
},
"aliases" : [ ],
"primary_terms" : {
"0" : 0
},
"in_sync_allocations" : {
"0" : [ ]
}
}
},
"index-graveyard" : {
"tombstones" : [ ]
}
},
"routing_table" : {
"indices" : {
"test" : {
"shards" : {
"0" : [
{
"state" : "STARTED",
"primary" : true,
"node" : "25457162-c5ef-44fa-a46b-a96434aae319",
"relocating_node" : null,
"shard" : 0,
"index" : "test",
"token_ranges" : [
"(-9223372036854775808,9223372036854775807]"
],
"allocation_id" : {
"id" : "dummy_alloc_id"
}
}
]
}
}
}
},
"routing_nodes" : {
"unassigned" : [ ],
"nodes" : {
"25457162-c5ef-44fa-a46b-a96434aae319" : [
{
"state" : "STARTED",
"primary" : true,
"node" : "25457162-c5ef-44fa-a46b-a96434aae319",
"relocating_node" : null,
"shard" : 0,
"index" : "test",
"token_ranges" : [
"(-9223372036854775808,9223372036854775807]"
],
"allocation_id" : {
"id" : "dummy_alloc_id"
}
}
]
}
},
"snapshots" : {
"snapshots" : [ ]
},
"restore" : {
"snapshots" : [ ]
},
"snapshot_deletions" : {
"snapshot_deletions" : [ ]
}
}

index정보 확인

curl "http://localhost:9200/_cat/indices?v"

health status index uuid                   pri rep docs.count docs.deleted store.size pri.store.size
green open test BOolxI89SqmrcbK7KM4sIA 1 0 4 0 4.1kb 4.1kb

인덱스 삭제(카산드라 테이블은 삭제안됨)

curl -XDELETE http://localhost:9200/test
{"acknowledged":true}