Created
February 28, 2019 15:04
-
-
Save ukn/410700fc8fd30590e18e6fa827557da7 to your computer and use it in GitHub Desktop.
Dirty way of getting elasticsearch index data for debugging
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
# Don't use in PROD! | |
# Script params: | |
# ES_URL - https://your-elasticseach-url.local | |
# INDEX - your-index-name | |
ES_URL=$1 | |
INDEX=$2 | |
SUFFIX=0 | |
curl -s -XPOST "${ES_URL}/${INDEX}/_search?scroll=10m&size=10000&pretty=true" >./${INDEX}-${SUFFIX} | |
echo "Data fetch for index ${INDEX} completed. Counter: ${SUFFIX}" | |
ID="{`head -2 ${INDEX}-${SUFFIX} | tail -1 | tr -d ','|sed -e 's/_scroll_id/scroll_id/g'`}" | |
while true; do | |
COUNT=`jq '.hits.hits | length' ./${INDEX}-${SUFFIX}` | |
if [[ $COUNT -eq 0 ]]; then | |
echo "Reached end of the index" | |
rm ./${INDEX}-${SUFFIX} | |
exit 0 | |
fi | |
SUFFIX=$((SUFFIX + 1)) | |
curl -s --fail -XPOST -H 'Content-Type:application/json' "${ES_URL}/_search/scroll?pretty=true&scroll=10m" --data "${ID}" >./${INDEX}-${SUFFIX} | |
echo "Data fetch for index ${INDEX} completed. Counter: ${SUFFIX}" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment