As mentioned above, the main API is probably the way to go. To convert a file for a mass protocol, you can use jq .
Assuming the file contains only the documents themselves:
$ echo '{"foo":"bar"}{"baz":"qux"}' | jq -c ' { index: { _index: "myindex", _type: "mytype" } }, . ' {"index":{"_index":"myindex","_type":"mytype"}} {"foo":"bar"} {"index":{"_index":"myindex","_type":"mytype"}} {"baz":"qux"}
And if the file contains documents in the top-level list, they must be unpacked first:
$ echo '[{"foo":"bar"},{"baz":"qux"}]' | jq -c ' .[] | { index: { _index: "myindex", _type: "mytype" } }, . ' {"index":{"_index":"myindex","_type":"mytype"}} {"foo":"bar"} {"index":{"_index":"myindex","_type":"mytype"}} {"baz":"qux"}
Flag
jq -c ensures that each document is on its own line.
If you want to directly scroll the pipe, you need to use --data-binary @- , and not just -d , otherwise the curl will again separate newline characters.
Peter Jun 17 '15 at 18:01 2015-06-17 18:01
source share