[๐ŸŒŽelasticsearch] Elasticsearch bulk ๊ธฐ๋ณธ์‚ฌ์šฉ๋ฒ• (feat. Kibana)

Park Ji Youngยท2021๋…„ 1์›” 13์ผ
0

elasticsearch

๋ชฉ๋ก ๋ณด๊ธฐ
4/8
post-thumbnail
post-custom-banner


์ด๋ฒˆ์—๋Š” ์‰ฌ์–ด๊ฐ€๋Š” ํƒ€์ž„์œผ๋กœ bulk ๊ธฐ๋Šฅ์„ ์•Œ์•„๋ณด์ฃ ~!
ํ•˜์ง€๋งŒ ๋ฐ˜๋“œ์‹œ ํ•„์ˆ˜ ์š”์†Œ๋ผ๋Š”๊ฒƒ !!

๐Ÿšš๐Ÿšš Bulk One Shot!!

ElasticSearch ์˜ ์—ฌ๋Ÿฌ ๋ช…๋ น์„ ์‹คํ–‰ํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” bulk ๊ธฐ๋Šฅ์ด ์ •๋ง ํŽธ๋ฆฌํ•ฉ๋‹ˆ๋‹ค.
bulk ๋Š” ๊ธฐ๋ณธ์ ์ธ CRUD ๋ช…๋ น ์ˆ˜ํ–‰์ด ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.

๋ฐ”๋กœ ์˜ˆ๋ฅผ ๋ณด์‹œ์ฃ !

POST _bulk
{ "index" : { "_index" : "test", "_id" : "1" } }
{ "field1" : "value1" }
{ "delete" : { "_index" : "test", "_id" : "2" } }
{ "create" : { "_index" : "test", "_id" : "3" } }
{ "field1" : "value3" }
{ "update" : {"_id" : "1", "_index" : "test"} }
{ "doc" : {"field2" : "value2"} }
  • bulk ๊ธฐ๋Šฅ์€ POST ๋ฉ”์†Œ๋“œ๋กœ "POST url/_bulk" ๋กœ ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.

    kibana๋กœ ํ…Œ์ŠคํŠธ ํ•˜์‹œ๋Š” ๊ฒฝ์šฐ url์„ ๋”ฐ๋กœ ์ง€์ •์•ˆํ•ด์ฃผ์…”๋„ ๋ฉ๋‹ˆ๋‹ค.
    ์ปค๋งจ๋“œ๋กœ ํ•˜์‹œ๋Š” ๊ฒฝ์šฐ๋Š” POST localhost:9200/_bulk ๋กœ ์‚ฌ์šฉ๊ฐ€๋Šฅํ•˜์‹ญ๋‹ˆ๋‹ค!

  • ์ดํ›„์— Request Body ๋ฅผ ํฌํ•จํ•˜์—ฌ ์š”์ฒญ์„ ์ „์†กํ•ด์•ผํ•ฉ๋‹ˆ๋‹ค.

    • create, index, update, delete ๊ธฐ๋Šฅ์€ ํ•ด๋‹น ํ‚ค์›Œ๋“œ ์•ˆ์— curly brace ๋กœ ๋ฌถ์Šต๋‹ˆ๋‹ค.
    • curly brace ์•ˆ์—๋Š” _index ๋กœ์„œ ์›ํ•˜๋Š” ์ธ๋ฑ์Šค, _id๋กœ ์›ํ•˜๋Š” id๋ฅผ ์ง€์ •ํ•˜์—ฌ ๊ธฐ๋Šฅ์„ ์ˆ˜ํ–‰ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
    • delete ๋ฅผ ์ œ์™ธํ•œ create, index, update ๋‹ค์Œ์—๋Š” ํ•œ ์ค„์˜ curly brace ๋‹จ๊ณ„๊ฐ€ ๋” ์žˆ๋Š”๋ฐ์š”. ์ด๋Š” ์›ํ•˜๋Š” ๊ธฐ๋Šฅ์„ ์ˆ˜ํ–‰ํ•˜๊ธฐ ์œ„ํ•ด ์ถ”๊ฐ€ํ•˜๋Š” ํ•„๋“œ์ž…๋‹ˆ๋‹ค.
    • index ์™€ create ์˜ ๊ฒฝ์šฐ์—๋Š” "field" ํ‚ค์›Œ๋“œ๊ฐ€ ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.
    • update ์˜ ๊ฒฝ์šฐ์—๋Š” ์ถ”๊ฐ€ ํ•„๋“œ์— "doc" ํ‚ค์›Œ๋“œ๋ฅผ ์ด์šฉํ•ด์„œ ์ ‘๊ทผํ•˜์…”์•ผ ํ•ฉ๋‹ˆ๋‹ค.

์†๋„๋Š” ๐Ÿš€๐Ÿš€

๊ธฐ๋ณธ์ ์œผ๋กœ ํ•œ ๋ฒˆ์˜ ๋Œ€๋Ÿ‰์˜ ๋ช…๋ น ๋ฐ์ดํ„ฐ๋ฅผ ์‹คํ–‰ํ•  ๋•Œ๋Š” bulk ๊ธฐ๋Šฅ์„ ์“ฐ๋Š” ๊ฒƒ์ด ์†๋„๊ฐ€ ๋น ๋ฆ…๋‹ˆ๋‹ค.
์ตœ์ ์˜ ๋ฐ์ดํ„ฐ ๋ช…๋ น ์ˆ˜๋ฅผ ์•Œ๊ธฐ ์œ„ํ•ด์„œ๋Š” ๋ฒค์น˜๋งˆํฌ๋ฅผ ์ด์šฉํ•˜์—ฌ ์ฒ˜์Œ์—๋Š” 100, 200, 400 ์œผ๋กœ ๋Š˜๋ ค๊ฐ€๋ฉฐ ํ…Œ์ŠคํŠธ ํ•ด๋ณด๋Š” ๊ฒƒ์„ ์ถ”์ฒœ๋“œ๋ฆฝ๋‹ˆ๋‹ค!! ์–ด๋Š์ •๋„ ๋Š˜๋ ธ์„ ๋•Œ ์†๋„๊ฐ€ ์ด์ „ ๋‹จ๊ณ„๋ณด๋‹ค ๋งค์šฐ ์™„ํ™”๋œ ์ƒํƒœ๋ผ๋ฉด ๊ทธ ์ „๋‹จ๊ณ„๊ฐ€ ์ตœ์ ํ™”๋œ ๋ช…๋ น ๊ฐœ์ˆ˜์ž…๋‹ˆ๋‹ค.

๋„ˆ๋ฌด ๋งŽ์€ ๋ช…๋ น ๋ฐ์ดํ„ฐ๋ฅผ ์‚ฌ์šฉํ•˜๊ฒŒ ๋˜๋ฉด ํด๋Ÿฌ์Šคํ„ฐ์˜ ๋ฉ”๋ชจ๋ฆฌ์— ๊ณผ๋ถ€ํ•˜๋ฅผ ์ฃผ๊ฒŒ๋˜๋‹ˆ ๋ช…์‹ฌํ•˜์„ธ์š”!

์ •๋ง ๊ณต๋ถ€ํ•  ์ˆ˜๋ก ํ›Œ๋ฅญํ•œ ๊ฒ€์ƒ‰์—”์ง„์ž…๋‹ˆ๋‹ค. ์›น ๊ณต๋ถ€๋ฅผ ํ•˜์‹œ๋Š” ๋ถ„์€ ElasticSearch๋ฅผ ๋ฌด์กฐ๊ฑด ๊ฐ•์ถ”!! ํ•˜๋Š”๋ฐ”์ž…๋‹ˆ๋‹ค ^^

profile
I am two cat's father
post-custom-banner

0๊ฐœ์˜ ๋Œ“๊ธ€