๐งฐ ์ธ๋ฑ์ค(`/contents`)์์ ๊ฐ๋ฅํ ์์ ๋ชฉ๋ก
์ด ๋ฌธ์๋
http://localhost:9200/contents
์ธ๋ฑ์ค๋ฅผ ๊ธฐ์ค์ผ๋ก
Elasticsearch์์ ์ํํ ์ ์๋ ๋ฌธ์ ์์ ๋ถํฐ ๊ณ ๊ธ ์ธ๋ฑ์ค ๊ด๋ฆฌ ๊ธฐ๋ฅ๊น์ง ์ ๋ฆฌํ ๋ฌธ์์ ๋๋ค.
โ 1. ๊ธฐ๋ณธ ๋ฌธ์ ์์
๐ฅ ๋ฌธ์ ์์ฑ (Create)
PUT http://localhost:9200/contents/_doc/1
{
"title": "Elasticsearch ๊ธฐ๋ณธ ๊ฐ๋
",
"author": "laon",
"createdAt": "2025-07-11"
}
๐ค ๋ฌธ์ ์กฐํ (Read)
GET http://localhost:9200/contents/_doc/1
๐ ๋ฌธ์ ์์ (Update)
POST http://localhost:9200/contents/_update/1
{
"doc": {
"author": "laon-ez"
}
}
โ ๋ฌธ์ ์ญ์ (Delete)
DELETE http://localhost:9200/contents/_doc/1
โ 2. ๋งคํ ์ ๋ณด ํ์ธ
๐ ๋งคํ ํ์ธ
GET http://localhost:9200/contents/_mapping?pretty
โ 3. ์ธ๋ฑ์ค ์ค์ ๊ด๋ฆฌ
โ๏ธ ์ค์ ๋ณ๊ฒฝ (์: refresh_interval ์กฐ์ )
PUT http://localhost:9200/contents/_settings
{
"index": {
"refresh_interval": "30s"
}
}
โ 4. Bulk Insert (๋๋ ์ฝ์ )
POST http://localhost:9200/contents/_bulk
{ "index": { "_id": "1" } }
{ "title": "๋ฌธ์ A", "views": 10 }
{ "index": { "_id": "2" } }
{ "title": "๋ฌธ์ B", "views": 5 }
โป ํค๋๋ Content-Type: application/x-ndjson
โ 5. ํต๊ณ ํ์ธ
๐ ๋ฌธ์ ์, ์ธ๋ฑ์ค ํฌ๊ธฐ ๋ฑ
GET http://localhost:9200/contents/_stats
โ 6. ๊ณ ๊ธ ์ธ๋ฑ์ค ๊ด๋ฆฌ ๊ธฐ๋ฅ
๐ท๏ธ 1. Alias ์ค์
POST http://localhost:9200/_aliases
{
"actions": [
{ "add": { "index": "contents", "alias": "contents_read" } }
]
}
๐ 2. Reindex (์ธ๋ฑ์ค ์ฌ๊ตฌ์ฑ)
POST http://localhost:9200/_reindex
{
"source": { "index": "old_contents" },
"dest": { "index": "contents" }
}
๐ 3. Rollover (์ธ๋ฑ์ค ์๋ ์ ํ)
POST http://localhost:9200/alias-contents/_rollover
{
"conditions": {
"max_docs": 1000,
"max_age": "7d"
}
}
๐ฆ 4. Index Template ์ ์ฉ
PUT http://localhost:9200/_index_template/content_template
{
"index_patterns": ["contents-*"],
"template": {
"settings": {
"number_of_shards": 1
},
"mappings": {
"properties": {
"title": { "type": "text" }
}
}
}
}
โณ 5. ILM (Index Lifecycle Management)
- rollover, delete, shrink ๋ฑ ์ธ๋ฑ์ค ์๋ช ์ฃผ๊ธฐ ๊ด๋ฆฌ
- ์ค์ต ์์๋
ilm_policy
์index template
์ฐ๊ณ ํ์
๐งพ ์์ฝ
๋ฒ์ฃผ | ๊ธฐ๋ฅ ์์ |
---|---|
๊ธฐ๋ณธ CRUD | GET / PUT / DELETE / UPDATE ๋ฌธ์ |
๋งคํ & ์ค์ | _mapping , _settings |
๋๋ ์์ | _bulk , _update_by_query |
ํต๊ณ ํ์ธ | _stats , _segments , _count |
๊ณ ๊ธ ๊ธฐ๋ฅ | alias, rollover, reindex, template, ILM |