#!/bin/bash

function fatal {
   echo 1>&2 "$*"
   exit 1
}

if [ ! -f accounts.json ] ; then
    fatal "This must be run in the same folder as the accounts.json file"
fi

esearchinfo="$(ps aux|grep -v grep | grep 'org.elasticsearch.bootstrap.Elasticsearch')"
if [ "${esearchinfo}"x = ""x ]; then
    fatal "You must have an elasticsearch instance already running. Aborting ..."
fi

# see: https://www.elastic.co/guide/en/elasticsearch/reference/current/_exploring_your_data.html
curl >/dev/null --fail --silent --show-error -s -XPOST "localhost:9200/bank/account/_bulk" --data-binary "@accounts.json"

