1

I have an instance of elasticsearch running inside a Docker-container.

For testing purposes I would like to initialize the db with a set of data. Similar to postgres where one could write .sql files which where executed on container startup. What is the best way to accomplish this with elasticsearch?

1
  • You can map the elasticsearch data folder as a volume inside your Docker container. Commented Sep 28, 2017 at 14:04

1 Answer 1

2

I have used the Bulk API to initialize Elasticsearch with test data.

The gist of it is, you create a Newline delimited JSON file, as required by the Bulk API, like this:

{ "index" : { "_index" : "test", "_type" : "type1", "_id" : "1" } }
{ "field1" : "value1" }

(Note the newline at the end of the file. It won't work without it.)

Then upload it to the bulk endpoint, which can be done with curl, like so:

curl -X POST --data-binary '@test-data.json' \
    -H 'Content-Type: application/x-ndjson' 'localhost:9200/_bulk?pretty'
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.