-
Notifications
You must be signed in to change notification settings - Fork 4
/
elastic-init.sh
executable file
·54 lines (46 loc) · 2.31 KB
/
elastic-init.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/bin/sh
# Wait for Elasticsearch to start up before doing anything
until curl -X GET "$ELASTIC_HOST/_cluster/health" | grep -q '"status":"green"\|"status":"yellow"'; do
echo "Waiting for Elasticsearch..."
sleep 5
done
ABSOLUTE_FILEPATH="${ELASTIC_FILEPATH//TAGPLACEHOLDER/$ELASTIC_GIT_TAG}$ELASTIC_FILENAME"
echo "Downloading $ABSOLUTE_FILEPATH"
response_onto_dl=$(curl --write-out "%{http_code}" -sLO "$ABSOLUTE_FILEPATH")
if [ "$response_onto_dl" -ne 200 ]; then
echo "Could not download ontology file. Maybe the tag $ELASTIC_GIT_TAG does not exist? Error code was $response_onto_dl"
exit 1
fi
unzip -o "$ELASTIC_FILENAME"
if [ "$OVERRIDE_EXISTING" = "true" ]; then
echo "(Trying to) delete existing indices"
curl --request DELETE "$ELASTIC_HOST/ontology"
curl --request DELETE "$ELASTIC_HOST/codeable_concept"
fi
echo "Creating ontology index..."
response_onto=$(curl --write-out "%{http_code}" -s --output /dev/null -XPUT -H 'Content-Type: application/json' "$ELASTIC_HOST/ontology" -d @elastic/ontology_index.json)
echo "Creating codeable concept index..."
response_cc=$(curl --write-out "%{http_code}" -s --output /dev/null -XPUT -H 'Content-Type: application/json' "$ELASTIC_HOST/codeable_concept" -d @elastic/codeable_concept_index.json)
echo "Done"
for FILE in elastic/*; do
if [ -f "$FILE" ]; then
BASENAME=$(basename "$FILE")
if [[ $BASENAME == onto_es__ontology* && $BASENAME == *.json ]]; then
if [[ "$response_onto" -eq 200 || "$OVERRIDE_EXISTING" = "true" ]]; then
echo "Uploading $BASENAME"
curl -s --output /dev/null -XPOST -H 'Content-Type: application/json' --data-binary @"$FILE" "$ELASTIC_HOST/ontology/_bulk"
else
echo "Skipping $BASENAME because index was already existing. Set OVERRIDE_EXISTING to true to force creating a new index"
fi
fi
if [[ $BASENAME == onto_es__codeable_concept* && $BASENAME == *.json ]]; then
if [[ "$response_cc" -eq 200 || "$OVERRIDE_EXISTING" = "true" ]]; then
echo "Uploading $BASENAME"
curl -s --output /dev/null -XPOST -H 'Content-Type: application/json' --data-binary @"$FILE" "$ELASTIC_HOST/codeable_concept/_bulk"
else
echo "Skipping $BASENAME because index was already existing. Set OVERRIDE_EXISTING to true to force creating a new index"
fi
fi
fi
done
echo "All done"