9
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【elasticsearch】コマンド一つで大量データをindexに追加する

Last updated at Posted at 2019-04-03

elasticsearch6.6.0で実施。

今回は一度に2件登録する仕様。
必要な分記述すればその数分登録できる。

##IDを指定する場合

bulk.json
{ "index" : {"_id" : "1" } }
{ "field1": "hoge1", "field2": "hoge2", "field3": "hoge3" }
{ "index" : {"_id" : "2" } }
{ "field1": "hoge1", "field2": "hoge2", "field3": "hoge3" }

curl -H "Content-Type: application/json" -X POST http://localhost:9200/index名/type名/_bulk?pretty --data-binary @bulk.json

##IDを指定しない場合
自動でIDが振られる。

bulk.json
{ "index" : {} }
{ "field1": "hoge1", "field2": "hoge2", "field3": "hoge3" }
{ "index" : {} }
{ "field1": "hoge1", "field2": "hoge2", "field3": "hoge3" }


curl -H "Content-Type: application/json" -X POST http://localhost:9200/index名/type名/_bulk?pretty --data-binary @bulk.json

##indexもtypeもidもjson内に記述する場合

bulk.json
{ "index" : { "_index" : "index名", "_type" : "type名", "_id" : "1" } }
{ "field1": "hoge1", "field2": "hoge2", "field3": "hoge3" }

curl -H "Content-Type: application/json" -X POST http://localhost:9200/_bulk?pretty --data-binary @bulk.json

応用

以下の記事で、jsonをpythonで自動生成するプログラムも紹介してます。
【elasticsearch】【python】bulk APIで使うjsonをcsvから動的に生成する

9
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?