35 lines
1 KiB
Bash
35 lines
1 KiB
Bash
|
#!/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"
|