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_part1/upload.sh

33 lines
1 KiB
Bash
Raw Normal View History

2023-04-24 07:49:04 +00:00
#!/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"