eris

- Elasticsearch Recon Ingestion Scripts (ERIS) 🔎
git clone git://git.acid.vegas/eris.git
Log | Files | Refs | Archive | README | LICENSE

es_index_dump (1009B)

      1 #!/bin/sh
      2 # ElasticSearch Index Dumper - developed by acidvegas (https://git.acid.vegas/eris)
      3 
      4 # This script will dump the entire contents of an ElasticSearch index to a JSON file.
      5 #
      6 # Todo:
      7 # - Add authentication support
      8 
      9 # Configuration
     10 BATCH_SIZE=10000
     11 ES_HOST="https://elastic.change.me:9200"
     12 ES_INDEX="juicy_booties"
     13 
     14 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')
     15 
     16 count=0
     17 
     18 while true; do
     19 	RESPONSE=$(curl -s -XGET "$ES_HOST/_search/scroll" -H 'Content-Type: application/json' -d"{\"scroll\": \"1m\", \"scroll_id\": \"$SCROLL_ID\"}")
     20 
     21 	HITS=$(echo $RESPONSE | jq -c '.hits.hits[]')
     22 
     23 	if [ -z "$HITS" ] || [ "$HITS" = "null" ]; then
     24 		break
     25 	fi
     26 
     27 	echo $HITS | jq -c '._source' >> $ES_INDEX.json
     28 
     29 	SCROLL_ID=$(echo $RESPONSE | jq -r '._scroll_id')
     30 
     31 	count=$(($count + $BATCH_SIZE))
     32 	echo "Dumped $BATCH_SIZE records ($count total) from $ES_INDEX on $ES_HOST"
     33 done