This repository has been archived by the owner on Oct 2, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
loadDataIntoElasticsearch.sh
140 lines (98 loc) · 4.26 KB
/
loadDataIntoElasticsearch.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/usr/bin/env bash
set -e
function startLoad {
echo "Start loading data into elasticsearch ..."
source=$1
environment=$2
targetElasticUrl=http://es01-fdk-01-${environment}.regsys-nprd.brreg.no:9200
#targetElasticUrl=http://localhost:9200 #http://es01-fdk-01-${environment}.regsys-nprd.brreg.no:9200/
# targetElasticUrl=https://elasticsearch-fellesdatakatalog-${environment}.paas-nprd.brreg.no
if [ "$environment" == "ppe" ]
then
targetElasticUrl=https://elasticsearch-fellesdatakatalog-${environment}.paas.brreg.no
fi
if [ "$environment" == "ppe5" ]
then
targetElasticUrl=http://es01-fdk-01-prd.regsys-prd.brreg.no:9200
fi
if [ "$environment" == "localhost" ]
then
targetElasticUrl=http://localhost:9200
fi
if [ "$environment" == "st1" ] || [ "$environment" == "st2" ]
then
targetElasticUrl=http://es01-fdk-02-${environment}.regsys-nprd.brreg.no:9200
fi
echo "Source files to load : ${source}"
echo "Target elasticsearch environment: ${targetElasticUrl}"
DATETIME=`date "+%Y-%m-%dT%H_%M_%S"`
echo "Starting dump ${DATETIME}"
dcatSetting=`cat libraries/datastore/src/main/resources/dcat_settings.json`
loadDcat
loadScat
loadRegister
loadHarvest
ENDTIME=`date "+%Y-%m-%dT%H_%M_%S"`
echo "finished dump ${ENDTIME}"
}
function loadHarvest {
echo "******************"
echo "HARVEST"
echo "******************"
curl -XDELETE ${targetElasticUrl}/harvest
# skip first and last line in mappings
harvestCatMapping=`sed '1d;$d' libraries/datastore/src/main/resources/harvest_catalog_mapping.json`
harvestDatMapping=`sed '1d;$d' libraries/datastore/src/main/resources/harvest_dataset_mapping.json`
harvestLooMapping=`sed '1d;$d' libraries/datastore/src/main/resources/harvest_lookup_mapping.json`
harvestMetadata="{ \"settings\": ${dcatSetting}, \"mappings\": { ${harvestCatMapping}, ${harvestDatMapping}, ${harvestLooMapping} } }"
curl -XPUT ${targetElasticUrl}/harvest -d "$harvestMetadata}"
elasticdump --bulk=true --input=${source}_harvest.json --output=${targetElasticUrl}/harvest --type=data
}
function loadRegister {
echo "******************"
echo "REGISTER"
echo "******************"
curl -XDELETE ${targetElasticUrl}/register
elasticdump --bulk=true --input=${source}_register.json --output=${targetElasticUrl}/register --type=data
}
function loadScat {
echo "******************"
echo "SCAT"
echo "******************"
curl -XDELETE ${targetElasticUrl}/scat
scatMapping=`cat libraries/datastore/src/main/resources/scat_subject_mapping.json`
scatMetadata="{ \"settings\": ${dcatSetting}, \"mappings\": ${scatMapping} }"
curl -XPUT ${targetElasticUrl}/scat -d "${scatMetadata}"
elasticdump --bulk=true --input=${source}_scat.json --output=${targetElasticUrl}/scat --type=data
}
function loadDcat {
echo "******************"
echo "DCAT"
echo "******************"
echo -e "Delete dcat index: \n\t curl -XDELETE ${targetElasticUrl}/dcat"
curl -XDELETE ${targetElasticUrl}/dcat
echo -e "\nCreate index with mapping"
dcatMapping=`cat libraries/datastore/src/main/resources/dcat_dataset_mapping.json`
dcatMetadata="{ \"settings\": ${dcatSetting}, \"mappings\": ${dcatMapping} }"
curl -XPUT ${targetElasticUrl}/dcat -d "${dcatMetadata}"
# recreate data in target environment
echo -e "\nDump data into target environment"
elasticdump --bulk=true --input=${source}_dcat.json --output=${targetElasticUrl}/dcat --type=data
}
if [ -z "$1" -o -z "$2" ]
then
echo "This command loads data from previously dumped elasticsearch json-files into a target elasticsearch environment"
echo "Source files and target environment must be specified: ut1, st1, st2, tt1 ppe or prd"
echo "Example: loadDcatEnv.sh st2 localhost"
echo " will load content of st2_*.json files into environment elastic at localhost"
exit 1
fi
echo "This will delete elasticsearch index <dcat, scat, harvest and register> in $2 and attempt to load previously dumped index in $1 into elasticsearch"
read -r -p "Are you sure? [y/N] " response
if [[ "$response" =~ ^([yY][eE][sS]|[yY])+$ ]]
then
startLoad $1 $2
else
exit 1
fi
echo "Done";