Elasticsearch API 묶음처리 bulk

(Elasticsearch API bulk에서 넘어옴)

1 개요[ | ]

Elasticsearch API bulk
Elasticsearch Bulk API

2 예제1: 공식예제[ | ]

curl -X POST localhost:9200/_bulk -H 'kbn-xsrf: true' -H 'Content-Type: application/x-ndjson' -d'
{ "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"} }
'
root@localhost:~# curl localhost:9200/_cat/indices?v
health status index uuid pri rep docs.count docs.deleted store.size pri.store.size
root@localhost:~# curl -X POST localhost:9200/_bulk -H 'kbn-xsrf: true' -H 'Content-Type: application/x-ndjson' -d'
> { "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"} }
> '
{"took":912,"errors":false,"items":[{"index":{"_index":"test","_type":"_doc","_id":"1","_version":1,"result":"created","_shards":{"total":2,"successful":1,"failed":0},"_seq_no":0,"_primary_term":1,"status":201}},{"delete":{"_index":"test","_type":"_doc","_id":"2","_version":1,"result":"not_found","_shards":{"total":2,"successful":1,"failed":0},"_seq_no":1,"_primary_term":1,"status":404}},{"create":{"_index":"test","_type":"_doc","_id":"3","_version":1,"result":"created","_shards":{"total":2,"successful":1,"failed":0},"_seq_no":2,"_primary_term":1,"status":201}},{"update":{"_index":"test","_type":"_doc","_id":"1","_version":2,"result":"updated","_shards":{"total":2,"successful":1,"failed":0},"_seq_no":3,"_primary_term":1,"status":200}}]}
root@localhost:~# curl localhost:9200/_cat/indices?v
health status index uuid                   pri rep docs.count docs.deleted store.size pri.store.size
yellow open   test  TY1Tq2GyRvWwoL4TVEiUVA   1   1          2            2      8.7kb          8.7kb

3 예제2[ | ]

curl -X POST localhost:9200/_bulk -H 'kbn-xsrf: true' -H 'Content-Type: application/x-ndjson' -d'
{ "index" : { "_index" : "myindex01" } }
{ "hello" : "world" }
{ "index" : { "_index" : "myindex01" } }
{ "hello" : "world" }
{ "index" : { "_index" : "myindex01" } }
{ "hello" : "world" }
{ "index" : { "_index" : "myindex02" } }
{ "hello" : "world" }
{ "index" : { "_index" : "myindex02" } }
{ "hello" : "world" }
'
root@localhost:~# curl localhost:9200/_cat/indices?v
health status index uuid pri rep docs.count docs.deleted store.size pri.store.size
root@localhost:~# # curl -X POST localhost:9200/_bulk -H 'kbn-xsrf: true' -H 'Content-Type: application/x-ndjson' -d'
> { "index" : { "_index" : "myindex01" } }
> { "hello" : "world" }
> { "index" : { "_index" : "myindex01" } }
> { "hello" : "world" }
> { "index" : { "_index" : "myindex01" } }
> { "hello" : "world" }
> { "index" : { "_index" : "myindex02" } }
> { "hello" : "world" }
> { "index" : { "_index" : "myindex02" } }
> { "hello" : "world" }
> '
{"took":260,"errors":false,"items":[{"index":{"_index":"myindex01","_type":"_doc","_id":"viNJMm8B9f-ngQDSt7t5","_version":1,"result":"created","_shards":{"total":2,"successful":1,"failed":0},"_seq_no":0,"_primary_term":1,"status":201}},{"index":{"_index":"myindex01","_type":"_doc","_id":"vyNJMm8B9f-ngQDSt7t5","_version":1,"result":"created","_shards":{"total":2,"successful":1,"failed":0},"_seq_no":1,"_primary_term":1,"status":201}},{"index":{"_index":"myindex01","_type":"_doc","_id":"wCNJMm8B9f-ngQDSt7t5","_version":1,"result":"created","_shards":{"total":2,"successful":1,"failed":0},"_seq_no":2,"_primary_term":1,"status":201}},{"index":{"_index":"myindex02","_type":"_doc","_id":"wSNJMm8B9f-ngQDSt7t5","_version":1,"result":"created","_shards":{"total":2,"successful":1,"failed":0},"_seq_no":0,"_primary_term":1,"status":201}},{"index":{"_index":"myindex02","_type":"_doc","_id":"wiNJMm8B9f-ngQDSt7t5","_version":1,"result":"created","_shards":{"total":2,"successful":1,"failed":0},"_seq_no":2,"_primary_term":1,"status":201}}]}
root@localhost:~# curl localhost:9200/_cat/indices?v
health status index     uuid                   pri rep docs.count docs.deleted store.size pri.store.size
yellow open   myindex01 gs-Ad-juTVKtfyQ6dTsLOQ   1   1          3            0      3.5kb          3.5kb
yellow open   myindex02 eXrIJvHlSvGkhbUAf3_Qrw   1   1          2            0      3.4kb          3.4kb

4 같이 보기[ | ]

5 참고[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}