Elasticsearch bulkを使って複数ドキュメント登録
2913 ワード
Elasticsearchで一つ一つドキュメントを追加していくのが面倒だったため、jsonファイルを使って複数ドキュメントを追加していきます。
JSONファイル
sample.json
{"index":{}}
{"id": 1, "name": "じゃがりこ"}
{"index":{}}
{"id": 2, "name": "マイクポップコーン"}
{"index":{}}
{"id": 3, "name": "チョコあ〜んぱん"}
{"index":{}}
{"id": 4, "name": "茎わかめ"}
sample.json
{"index":{}}
{"id": 1, "name": "じゃがりこ"}
{"index":{}}
{"id": 2, "name": "マイクポップコーン"}
{"index":{}}
{"id": 3, "name": "チョコあ〜んぱん"}
{"index":{}}
{"id": 4, "name": "茎わかめ"}
一番下に一行空けないとエラーになってしまう。。
実行コマンド
# テンプレート
$ curl -H 'Content-Type: application/x-ndjson' -XPOST http://{domain}/{index}/_bulk?pretty --data-binary @{json file}.json
$ curl -H 'Content-Type: application/x-ndjson' -XPOST http://0.0.0.0:9200/snacks/_bulk?pretty --data-binary @sample.json
# テンプレート
$ curl -H 'Content-Type: application/x-ndjson' -XPOST http://{domain}/{index}/_bulk?pretty --data-binary @{json file}.json
$ curl -H 'Content-Type: application/x-ndjson' -XPOST http://0.0.0.0:9200/snacks/_bulk?pretty --data-binary @sample.json
Author And Source
この問題について(Elasticsearch bulkを使って複数ドキュメント登録), 我々は、より多くの情報をここで見つけました https://qiita.com/nanaco/items/0830439f84ed8d4a9d4b著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .