-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathsetup_local.sh
executable file
·142 lines (123 loc) · 4.41 KB
/
setup_local.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
141
142
#!/bin/bash
set -e
echo "collecting arguments..."
ES_VERSION=${1}
echo "Elasticsearch version: $ES_VERSION"
WDIR=$(pwd)
TESTDIR=${WDIR}/sandbox
SAMPLE_DATA_FILE=$(pwd)/test-data/sample.json
ES_HOST="127.0.0.1"
ES_PORT="9200"
echo "Starting up Elasticsearch..."
case "${ES_VERSION}" in
1.7.6)
docker run --rm -d -p "${ES_PORT}:9200" elasticsearch:1.7.6
MAPPING_FILE=$(pwd)/test-data/legacy_shakespeare_mapping.json
;;
2.4.6)
docker run --rm -d -p "${ES_PORT}:9200" elasticsearch:2.4.6
MAPPING_FILE=$(pwd)/test-data/legacy_shakespeare_mapping.json
;;
5.6.16)
docker run --rm -d -p "${ES_PORT}:9200" \
-e "xpack.security.enabled=false" \
docker.elastic.co/elasticsearch/elasticsearch:5.6.16
MAPPING_FILE=$(pwd)/test-data/es5_shakespeare_mapping.json
;;
6.8.15)
docker run --rm -d -p "${ES_PORT}:9200" \
-e "discovery.type=single-node" \
-e "xpack.security.enabled=false" \
docker.elastic.co/elasticsearch/elasticsearch:6.8.15
MAPPING_FILE=$(pwd)/test-data/es6_shakespeare_mapping.json
;;
7.0.1)
docker run --rm -d -p "${ES_PORT}:9200" \
-e "discovery.type=single-node" \
-e "xpack.security.enabled=false" \
docker.elastic.co/elasticsearch/elasticsearch:7.0.1
MAPPING_FILE=$(pwd)/test-data/es7_shakespeare_mapping.json
SAMPLE_DATA_FILE=$(pwd)/test-data/sample_es7.json
;;
7.17.22)
docker run --rm -d -p "${ES_PORT}:9200" \
-e "discovery.type=single-node" \
-e "xpack.security.enabled=false" \
docker.elastic.co/elasticsearch/elasticsearch:7.17.22
MAPPING_FILE=$(pwd)/test-data/es7_shakespeare_mapping.json
SAMPLE_DATA_FILE=$(pwd)/test-data/sample_es7.json
;;
8.0.1)
docker run --rm -d -p "${ES_PORT}:9200" \
-e "discovery.type=single-node" \
-e "xpack.security.enabled=false" \
docker.elastic.co/elasticsearch/elasticsearch:8.0.1
MAPPING_FILE=$(pwd)/test-data/es7_shakespeare_mapping.json
SAMPLE_DATA_FILE=$(pwd)/test-data/sample_es7.json
;;
8.5.3)
docker run --rm -d -p "${ES_PORT}:9200" \
-e "discovery.type=single-node" \
-e "xpack.security.enabled=false" \
docker.elastic.co/elasticsearch/elasticsearch:8.5.3
MAPPING_FILE=$(pwd)/test-data/es7_shakespeare_mapping.json
SAMPLE_DATA_FILE=$(pwd)/test-data/sample_es7.json
;;
8.10.4)
docker run --rm -d -p "${ES_PORT}:9200" \
-e "discovery.type=single-node" \
-e "xpack.security.enabled=false" \
docker.elastic.co/elasticsearch/elasticsearch:8.10.4
MAPPING_FILE=$(pwd)/test-data/es7_shakespeare_mapping.json
SAMPLE_DATA_FILE=$(pwd)/test-data/sample_es7.json
;;
8.15.5)
docker run --rm -d -p "${ES_PORT}:9200" \
-e "discovery.type=single-node" \
-e "xpack.security.enabled=false" \
docker.elastic.co/elasticsearch/elasticsearch:8.15.5
MAPPING_FILE=$(pwd)/test-data/es7_shakespeare_mapping.json
SAMPLE_DATA_FILE=$(pwd)/test-data/sample_es7.json
;;
8.17.2)
docker run --rm -d -p "${ES_PORT}:9200" \
-e "discovery.type=single-node" \
-e "xpack.security.enabled=false" \
docker.elastic.co/elasticsearch/elasticsearch:8.17.2
MAPPING_FILE=$(pwd)/test-data/es7_shakespeare_mapping.json
SAMPLE_DATA_FILE=$(pwd)/test-data/sample_es7.json
;;
*)
echo "Did not recognize version ${ES_VERSION}. Not starting Elasticsearch"
exit 1
;;
esac
echo "Elasticsearch v${ES_VERSION} is now running at http://${ES_HOST}:9200"
echo "Setting up local testing environment"
# Creating testing directory
mkdir -p "${TESTDIR}"
# Get data
cp "${MAPPING_FILE}" "${TESTDIR}/shakespeare_mapping.json"
cp "${SAMPLE_DATA_FILE}" "${TESTDIR}/sample.json"
cd "${TESTDIR}"
# give the cluster a chance
sleep 30
# Create shakespeare index and shakespeare mapping
curl -X PUT "http://${ES_HOST}:9200/shakespeare" \
-H 'Content-Type: application/json' \
-d @shakespeare_mapping.json
# Upload data
curl -X POST "http://${ES_HOST}:9200/shakespeare/_bulk" \
-H 'Content-Type: application/json' \
--data-binary @sample.json
# Add an intentionally empty index
curl -X PUT "http://${ES_HOST}:9200/empty_index" \
-H 'Content-Type: application/json' \
-d @shakespeare_mapping.json
# Refresh all indices
curl -X POST "http://${ES_HOST}:9200/_refresh"
# Check that we got something
curl -X GET "http://${ES_HOST}:9200/shakespeare/_search?size=1"
cd "${WDIR}"
echo ""
echo "Your local environment is ready."