temp=$(kubectl get svc -n imxc -o wide | grep elasticsearch | grep NodePort | awk {'print $5'})
export ES_NODEPORT=${temp:5:(-4)}
echo $ES_NODEPORT

export MASTER_IP=$(kubectl get nodes -o wide | grep master | awk {'print $6'})
echo $MASTER_IP

SOURCE_INDEX='kubernetes_event_info'
DEST_INDEX='kubernetes_event_info_backup'

curl -X GET 'http://'"${MASTER_IP}"':'"${ES_NODEPORT}"'/_cat/indices' | grep "${DEST_INDEX}" | awk '{print $3}' | while read line
do
        date=${line: (-11)}
        source_index_date=${SOURCE_INDEX}${date}
        dest_index_date=${DEST_INDEX}${date}

        echo $source_index_date
        echo $dest_index_date

        curl -X DELETE 'http://'"${MASTER_IP}"':'"${ES_NODEPORT}"'/'${source_index_date}

        curl -X POST 'http://'"${MASTER_IP}"':'"${ES_NODEPORT}"'/_reindex?wait_for_completion=false' -H 'Content-Type: application/json' -d '{
                "source": {
                        "index": "'${dest_index_date}'"
                },
                "dest": {
                        "index": "'${source_index_date}'"
                }
        }'
done
