2024-02-02 05:11:18 +00:00
|
|
|
#!/bin/sh
|
|
|
|
# ElasticSearch Index Dumper - developed by acidvegas (https://git.acid.vegas/eris)
|
|
|
|
|
|
|
|
# This script will dump the entire contents of an ElasticSearch index to a JSON file.
|
|
|
|
#
|
|
|
|
# Todo:
|
|
|
|
# - Add authentication support
|
|
|
|
|
|
|
|
# Configuration
|
|
|
|
BATCH_SIZE=10000
|
|
|
|
ES_HOST="https://elastic.change.me:9200"
|
|
|
|
ES_INDEX="juicy_booties"
|
|
|
|
|
2024-03-04 22:44:09 +00:00
|
|
|
SCROLL_ID=$(curl -s -XGET "$ES_HOST/$ES_INDEX/_search?scroll=1m" -H 'Content-Type: application/json' -d"{ \"size\": $BATCH_SIZE, \"query\": { \"match_all\": {} } }" | jq -r '._scroll_id')
|
2024-02-02 05:11:18 +00:00
|
|
|
|
|
|
|
count=0
|
|
|
|
|
|
|
|
while true; do
|
2024-03-04 22:44:09 +00:00
|
|
|
RESPONSE=$(curl -s -XGET "$ES_HOST/_search/scroll" -H 'Content-Type: application/json' -d"{\"scroll\": \"1m\", \"scroll_id\": \"$SCROLL_ID\"}")
|
|
|
|
|
2024-02-02 05:11:18 +00:00
|
|
|
HITS=$(echo $RESPONSE | jq -c '.hits.hits[]')
|
|
|
|
|
|
|
|
if [ -z "$HITS" ] || [ "$HITS" = "null" ]; then
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo $HITS | jq -c '._source' >> $ES_INDEX.json
|
|
|
|
|
|
|
|
SCROLL_ID=$(echo $RESPONSE | jq -r '._scroll_id')
|
|
|
|
|
|
|
|
count=$(($count + $BATCH_SIZE))
|
|
|
|
echo "Dumped $BATCH_SIZE records ($count total) from $ES_INDEX on $ES_HOST"
|
|
|
|
done
|