#!/bin/bash set -e SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) elastic_dir="$HOME/bin/elasticsearch-8.6.2" elastic_url="https://localhost:9200" crt="$elastic_dir/config/certs/http_ca.crt" input="$SCRIPT_DIR/data/restaurants.jsonl" password="GZH*wqNTvQ0WRdrPrpHm" # Create index curl --cacert "$crt" -u "elastic:$password" \ -X DELETE "$elastic_url/restaurants" | jq . || true curl --cacert "$crt" -u "elastic:$password" \ -X PUT "$elastic_url/restaurants" | jq . # Upload mappings cat mappings.json | curl --cacert "$crt" -u "elastic:$password" -X POST \ --data-binary @- "$elastic_url/restaurants/_mappings/" \ -H "Content-Type: application/json" | jq . # Upload documents one by one while IFS= read -r line do id=$(echo "$line" | jq '.id | tonumber') echo $line | curl -k --cacert "$crt" -u "elastic:$password" -X PUT \ --data-binary @- "$elastic_url/restaurants/_doc/$id" \ -H "Content-Type: application/json" | jq ._id & done < "$input"