-
Notifications
You must be signed in to change notification settings - Fork 1
/
et
executable file
·82 lines (72 loc) · 2.27 KB
/
et
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
#!/usr/bin/env bash
set -euo pipefail
if [ $# -ge 2 ]; then
action=$1
if [ "$action" == "index" ]; then
command=$2
if [ "$command" == create ]; then
index_version=${3:-0}
base_dir=${4:-index}
es_url=${5:-http://localhost:9200}
echo "PUT $es_url/$index_version"
curl -X PUT -H "Content-Type: application/json" -d "@$base_dir/$index_version/index.json" "$es_url/$index_version/?pretty"
echo "PUT $es_url/$index_version/_mapping/?pretty"
curl -X PUT -H "Content-Type: application/json" -d "@$base_dir/$index_version/mapping.json" "$es_url/$index_version/_mapping/movie?pretty"
fi
if [ "$command" == "delete" ]; then
index_version=${3:-0}
es_url=${4:-http://localhost:9200}
echo "DELETE $es_url/$index_version"
curl -X DELETE "$es_url/$index_version/?pretty"
fi
if [ "$command" == "alias" ]; then
alias=$3
add=$4
remove=${5-}
es_url=${6:-http://localhost:9200}
if [ -z ${remove} ]; then
payload="
{
\"actions\": [
{ \"add\": {
\"alias\": \"$alias\",
\"index\": \"$add\"
}}
]
}
"
else
payload="
{
\"actions\": [
{ \"add\": {
\"alias\": \"$alias\",
\"index\": \"$add\"
}},
{ \"remove\": {
\"alias\": \"$alias\",
\"index\": \"$remove\"
}}
]
}
"
fi
echo "$payload"
curl -X POST -H "Content-Type: application/json" "$es_url/_aliases?pretty" -d"$payload"
fi
fi
if [ "$action" == "reindex" ]; then
from=$2
to=$3
es_url=${4:-http://localhost:9200}
curl -X POST "$es_url/_reindex?pretty" -H "Content-type: application/json" -d "{
\"source\": {\"index\": \"$from\"},
\"dest\": {\"index\": \"$to\"}
}"
fi
else
echo "-- Elasticsearch Tool --"
echo "et index create name_of_my_index [ index_basedir ] [ elasticsearch url ]"
echo "et index delete name_of_my_index [ elasticsearch url]"
echo "et index alias alias_name index_name [ name_of_index_to_remove_alias ] [ elasticsearch url]"
fi