Skip to content

Instantly share code, notes, and snippets.

@ukn
Created February 28, 2019 15:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ukn/410700fc8fd30590e18e6fa827557da7 to your computer and use it in GitHub Desktop.
Save ukn/410700fc8fd30590e18e6fa827557da7 to your computer and use it in GitHub Desktop.
Dirty way of getting elasticsearch index data for debugging
#!/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