일괄 처리 작업, 배치 프로세스는 다량의 데이터를 한 번에 일괄적으로 처리하는 것을 말해요.

그럼 엘라스틱서치에서의 일괄 처리 작업, 배치 프로세스는 어떻게 될까요?

 

https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-bulk.html

 

Bulk API | Elasticsearch Guide [7.14] | Elastic

The final line of data must end with a newline character \n. Each newline character may be preceded by a carriage return \r. When sending NDJSON data to the _bulk endpoint, use a Content-Type header of application/json or application/x-ndjson.

www.elastic.co

엘라스틱서치에는 Bulk API가 해줍니다.

 

books 인덱스에 나머지 해리포터 시리즈도 다 올려볼게요.

POST /books/_bulk
{"create": {"_id":"HarryPotter-Book04"}}
{"title": "Harry Potter and the Goblet of Fire", "price": 44.99, "rating": 4.9, "in_stock": 24100}
{"create": {"_id":"HarryPotter-Book05"}}
{"title": "Harry Potter and the Order of the Phoenix", "price": 44.99, "rating": 4.9, "in_stock": 29767}
{"create": {"_id":"HarryPotter-Book06"}}
{"title": "Harry Potter and the Half-Blood Prince", "price": 44.99, "rating": 4.9, "in_stock": 26276}
{"create": {"_id":"HarryPotter-Book07"}}
{"title": "Harry Potter and the Deathly Hallows", "price": 44.99, "rating": 4.9, "in_stock": 28133}

이렇게 하나의 인덱스에 여러 개의 도큐먼트를 올릴 때는  POST /{인덱스이름}/_bulk 로 하면 아래 내용들에는 따로 인덱스 명은 넣지 않아도 돼요. 여러 인덱스에 bulk API로 넣을 때는

 

POST /_bulk

{"index": {"_index": "books", "_id": "HarryPotter-Book04"}}

{"title""Harry Potter and the Goblet of Fire""price"44.99"rating"4.9"in_stock"24100}

 

이렇게 해주면 돼요.

여기 index 부분은 create, index, delete, update와 같은 다양한  actions를 사용할 수 있어요.

그리고 create나 index를 할 때는 {"필드명": "필드값"} 형식으로 넣어주면 돼요.

 

이제 많은 데이터도 한 번에 딱 넣을 수 있겠지요?

cURL을 활용해서 벌크 작업을 할 수도 있어요. 그런데 너ㅜㅁ나 어렵고 복잡해요. 우리 키바나를 써주세요. 감사해요.

 

 

오늘은 여기까지.