๐Ÿงฐ ์ธ๋ฑ์Šค(`/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 ์—ฐ๊ณ„ ํ•„์š”

๐Ÿงพ ์š”์•ฝ

๋ฒ”์ฃผ๊ธฐ๋Šฅ ์˜ˆ์‹œ
๊ธฐ๋ณธ CRUDGET / PUT / DELETE / UPDATE ๋ฌธ์„œ
๋งคํ•‘ & ์„ค์ •_mapping, _settings
๋Œ€๋Ÿ‰ ์ž‘์—…_bulk, _update_by_query
ํ†ต๊ณ„ ํ™•์ธ_stats, _segments, _count
๊ณ ๊ธ‰ ๊ธฐ๋Šฅalias, rollover, reindex, template, ILM