This repository has been archived on 2024-10-22. You can view files and clone it, but cannot push or open issues or pull requests.
va/Assignment2_part2/upload.sh

35 lines
1 KiB
Bash
Raw Normal View History

#!/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_extended.jsonl"
password="GZH*wqNTvQ0WRdrPrpHm"
index_name="restaurants_extended"
# Create index
curl --cacert "$crt" -u "elastic:$password" \
-X DELETE "$elastic_url/$index_name" | jq . || true
curl --cacert "$crt" -u "elastic:$password" \
-X PUT "$elastic_url/$index_name" | jq .
# Upload mappings
cat mappings.json | curl --cacert "$crt" -u "elastic:$password" -X POST \
--data-binary @- "$elastic_url/$index_name/_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/$index_name/_doc/$id" \
-H "Content-Type: application/json" | jq ._id &
done < "$input"