2019-10-28 11:55:53 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
set -e
|
|
|
|
#set -x
|
|
|
|
|
|
|
|
function queryAPI() {
|
|
|
|
method=$1
|
|
|
|
path=$2
|
|
|
|
data=$3
|
|
|
|
cmd="curl -s -X${method} http://localhost:9200/${path}"
|
|
|
|
if [[ -n "${data}" ]]; then
|
|
|
|
cmd+=" -f -H 'content-type:application/json' -d '${data}'"
|
|
|
|
fi
|
|
|
|
eval "${cmd}"
|
|
|
|
}
|
|
|
|
|
|
|
|
function create() {
|
|
|
|
queryAPI PUT "${1}" '{"settings":{"number_of_replicas":1,"number_of_shards": 1}}'
|
|
|
|
}
|
|
|
|
|
|
|
|
function reindex() {
|
|
|
|
queryAPI POST "_reindex" "{\"source\":{\"index\":\"${1}\"},\"dest\":{\"index\":\"${2}\"}}"
|
|
|
|
}
|
|
|
|
|
|
|
|
function delete() {
|
|
|
|
queryAPI DELETE "${1}"
|
|
|
|
}
|
|
|
|
|
|
|
|
function stats() {
|
|
|
|
queryAPI GET "${1}/_stats"
|
|
|
|
}
|
|
|
|
|
|
|
|
function docs_count() {
|
|
|
|
stats "${1}" | jq '._all.primaries.docs.count'
|
|
|
|
}
|
|
|
|
|
|
|
|
function size_in_bytes() {
|
|
|
|
stats "${1}" | jq '._all.primaries.store.size_in_bytes / (1000*1000) | floor'
|
|
|
|
}
|
|
|
|
|
|
|
|
index="$1"
|
|
|
|
if [[ -z "${index}" ]]; then
|
|
|
|
echo "First argument has to be an index name!"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
old="${index}"
|
|
|
|
new="${index}-re"
|
|
|
|
echo "*------ ${old} -----------------------------------"
|
2019-10-28 12:49:06 +00:00
|
|
|
echo "? $(printf '%-23s' ${old}) - Count: $(docs_count ${old})"
|
|
|
|
echo "? $(printf '%-23s' ${old}) - Size: $(size_in_bytes ${old}) MB"
|
2019-10-28 11:55:53 +00:00
|
|
|
echo "+ Creating: ${new}"
|
2019-10-28 12:49:06 +00:00
|
|
|
create "${new}" > /dev/null
|
2019-10-28 11:55:53 +00:00
|
|
|
echo "+ Reindexing: ${old} -> ${new}"
|
2019-10-28 12:49:06 +00:00
|
|
|
reindex "${old}" "${new}" > /dev/null
|
|
|
|
echo "? $(printf '%-23s' ${new}) - Count: $(docs_count ${new})"
|
|
|
|
echo "? $(printf '%-23s' ${new}) - Size: $(size_in_bytes ${new}) MB"
|
2019-10-28 11:55:53 +00:00
|
|
|
echo "! Deleting: ${old}"
|
2019-10-28 12:49:06 +00:00
|
|
|
delete "${old}" > /dev/null
|
2019-10-28 11:55:53 +00:00
|
|
|
echo "+ Re-Reindexing: ${new} -> ${old}"
|
2019-10-28 12:49:06 +00:00
|
|
|
reindex "${new}" "${old}" > /dev/null
|
|
|
|
echo "? $(printf '%-23s' ${old}) - Count: $(docs_count ${old})"
|
|
|
|
echo "? $(printf '%-23s' ${old}) - Size: $(size_in_bytes ${old}) MB"
|
2019-10-28 11:55:53 +00:00
|
|
|
echo "! Deleting: ${new}"
|
2019-10-28 12:49:06 +00:00
|
|
|
delete "${new}" > /dev/null
|
2019-10-28 11:55:53 +00:00
|
|
|
echo "*------ ${old} -----------------------------------"
|