1
1
#! /bin/sh
2
-
3
- TEMPLATE_FILE=" /usr/share/elasticsearch/config/tabular_data_index_template.json"
4
- ES_URL=" http://elasticsearch:9200"
5
- AUTH=" -u elastic:myelasticpassword"
6
- INDEX_NAME=" tabular-index"
7
- TEMPLATE_NAME=" tabular_template"
8
- ALIAS_NAME=" tabular_centric"
2
+ ES_AUTH=" ${ES_USER} :${ES_PASS} "
9
3
10
4
# Check template file
11
- [ ! -f " $TEMPLATE_FILE " ] && printf " \033[1;31mError:\033[0m Template file not found at $TEMPLATE_FILE \n" && exit 1
5
+ [ ! -f " $TABULAR_ES_TEMPLATE_FILE " ] && printf " \033[1;31mError:\033[0m Template file not found at $TABULAR_ES_TEMPLATE_FILE \n" && exit 1
12
6
13
7
# Set up template if it doesn't exist
14
8
printf " \033[1;36mConductor:\033[0m Setting up the Elasticsearch tabular index template\n"
15
- if ! curl -s $AUTH " $ES_URL /_template/$TEMPLATE_NAME " | grep -q " \" index_patterns\" " ; then
16
- curl -s $AUTH -X PUT " $ES_URL /_template/$TEMPLATE_NAME " \
17
- -H " Content-Type: application/json" -d @" $TEMPLATE_FILE " > /dev/null && \
18
- printf " \033[1;32mSuccess:\033[0m Elasticsearch tabular index template created successfully\n"
9
+ if ! curl -s -u " $ES_AUTH " " $ES_URL /_template/$TABULAR_ES_TEMPLATE_NAME " | grep -q " \" index_patterns\" " ; then
10
+ curl -s -u " $ES_AUTH " -X PUT " $ES_URL /_template/$TABULAR_ES_TEMPLATE_NAME " \
11
+ -H " Content-Type: application/json" -d @" $TABULAR_ES_TEMPLATE_FILE " > /dev/null && \
12
+ printf " \033[1;32mSuccess:\033[0m Elasticsearch tabular index template created successfully\n"
19
13
else
20
- printf " \033[1;36mElasticsearch (Tabular):\033[0m Tabular Index template already exists, skipping creation\n"
14
+ printf " \033[1;36mElasticsearch (Tabular):\033[0m Tabular Index template already exists, skipping creation\n"
21
15
fi
22
16
23
17
# Create index with alias if it doesn't exist
24
18
printf " \033[1;36mConductor:\033[0m Setting up the Elasticsearch tabular index and alias\n"
25
- if ! curl -s -f $AUTH -X GET " $ES_URL /$INDEX_NAME " > /dev/null 2>&1 ; then
26
- printf " \033[1;36mElasticsearch (Tabular):\033[0m Index does not exist, creating tabular index\n"
27
- response=$( curl -s -w " \n%{http_code}" $AUTH -X PUT " $ES_URL /$INDEX_NAME " \
28
- -H " Content-Type: application/json" \
29
- -d " {\" aliases\" : {\" $ALIAS_NAME \" : {}}}" )
30
-
31
- http_code=$( echo " $response " | tail -n1)
32
- if [ " $http_code " != " 200" ] && [ " $http_code " != " 201" ]; then
33
- printf " \033[1;31mError:\033[0m Failed to create tabular index. HTTP Code: $http_code \n"
34
- exit 1
35
- fi
36
- printf " \033[1;32mSuccess:\033[0m Tabular index and alias created\n"
19
+ if ! curl -s -f -u " $ES_AUTH " -X GET " $ES_URL /$TABULAR_INDEX_NAME " > /dev/null 2>&1 ; then
20
+ printf " \033[1;36mElasticsearch (Tabular):\033[0m Index does not exist, creating tabular index\n"
21
+ response=$( curl -s -w " \n%{http_code}" -u " $ES_AUTH " -X PUT " $ES_URL /$TABULAR_INDEX_NAME " \
22
+ -H " Content-Type: application/json" \
23
+ -d " {\" aliases\" : {\" $TABULAR_ES_ALIAS_NAME \" : {}}}" )
24
+
25
+ http_code=$( echo " $response " | tail -n1)
26
+ if [ " $http_code " != " 200" ] && [ " $http_code " != " 201" ]; then
27
+ printf " \033[1;31mError:\033[0m Failed to create tabular index. HTTP Code: $http_code \n"
28
+ exit 1
29
+ fi
30
+ printf " \033[1;32mSuccess:\033[0m Tabular index and alias created\n"
37
31
else
38
- printf " \033[1;36mElasticsearch (Tabular):\033[0m Tabular index already exists\n"
32
+ printf " \033[1;36mElasticsearch (Tabular):\033[0m Tabular index already exists\n"
39
33
fi
40
34
41
35
printf " \033[1;32mSuccess:\033[0m Elasticsearch tabular setup complete\n"
0 commit comments