Elasticsearch Bulk JSON Data

前端 未结 1 593
死守一世寂寞
死守一世寂寞 2020-12-02 00:47

This question arises from this SO thread.

As it seems I have a similar but not the same query, it might be best to have a separate question for others to benefit fro

相关标签:
1条回答
  • 2020-12-02 01:11

    You can transform your file very easily with a single shell command like this. Provided that your file is called input.json, you can do this:

    jq -c -r ".[]" input.json | while read line; do echo '{"index":{}}'; echo $line; done > bulk.json
    

    After this you'll have a file called bulk.json which is properly formatted to be sent to the bulk endpoint.

    Then you can call your bulk endpoint like this:

    curl -XPOST localhost:9200/your_index/your_type/_bulk -H "Content-Type: application/x-ndjson" --data-binary @bulk.json
    

    Note: You need to install jq first if you don't have it already.

    0 讨论(0)
提交回复
热议问题