-
Notifications
You must be signed in to change notification settings - Fork 32
/
migrate.sh
executable file
·65 lines (57 loc) · 1.66 KB
/
migrate.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
#!/bin/bash
# If the environment file does not exist, create it based on example.env
if [ ! -f .env ]; then
echo "Warning: File .env not found, copying from example.env"
cp example.env .env
fi
# Parse the environment variables from .env file, ignoring the comments
export $(cat .env | grep -v ^# | xargs)
curl --cacert ${ES_CA_CERTS} --user ${ES_USERNAME}:${ES_PASSWORD} \
-XPUT "${ES_URL}_ingest/pipeline/convert_boolean" \
-H 'Content-Type: application/json' -d'
{
"description" : "Converts numeric booleans to true or false",
"processors" : [
{
"script": {
"source": "if (ctx.is_fake != null) { ctx.is_fake = ctx.is_fake == 1; } if (ctx.is_banned != null) { ctx.is_banned = ctx.is_banned == 1; }"
}
}
]
}'
for YEAR in {2018..2024}; do
for MONTH in 01 02 03 04 05 06 07 08 09 10 11 12; do
INDEX_NAME="tor-$YEAR-$MONTH"
echo ""
echo $INDEX_NAME
echo ""
sleep 3
JSON_PAYLOAD=$(cat <<EOF
{
"source": {
"size": 50,
"remote": {
"host": "http://localhost:19200"
},
"index": "${INDEX_NAME}",
"query": {
"match_all": {}
}
},
"dest": {
"index": "${INDEX_NAME}",
"pipeline": "convert_boolean"
},
"script": {
"source": "if (ctx._source.containsKey('raw_text')) {ctx._source.remove('raw_text');} if (ctx._source.containsKey('raw_title')) {ctx._source.remove('raw_title');} if (ctx._source.containsKey('raw_url')) {ctx._source.remove('raw_url');}",
"lang": "painless"
}
}
EOF
)
curl --cacert ${ES_CA_CERTS} --user ${ES_USERNAME}:${ES_PASSWORD} \
-XPOST "${ES_URL}_reindex?pretty" \
-H 'Content-Type: application/json' -d "$JSON_PAYLOAD"
echo ""
done
done