Skip to content

Instantly share code, notes, and snippets.

View thanthos's full-sized avatar

James Tang thanthos

  • Zeus View
  • Singapore
View GitHub Profile
@thanthos
thanthos / reindex.sh
Last active February 26, 2016 06:26
Reindexing Strategy using 3 files.
#Reindexing your Elasticsearch indice with limited resource can be a painw when you have limited resources and need it running at the same time
#Hence it is advisable to size up the quantity and break it down into chunks based on time.
#Look to Kibana. The break down is already done for you even as you perform your search.
#Just pop up the request and the aggregation query is there.
#Using this, you can tally your document count according to time to verify your activities.
#I need to do this as due to resource constrains. Logstash input plugin sometimes hit into error and the plugin restart.
#When it restarts the query get executed again. With logstash plugin-input-Elasticsearch, it resume a new search.
#Any previous scroll ID is discarded. This is something you do not want happening.
#You can end up with more document in the target than the source. #Thus breaking it down to chucks limit the corruption and makes remediation easier.
@thanthos
thanthos / reindex.js
Last active February 25, 2016 02:59
This is a Javascript which helps with the extraction of data in elastic search. Somehow, this script uses less memory than the default Logstash. ( I encountered errors with logstash but not with Javascripts. ) This iteration of the script is single threaded and more for someone who knows how to write Javascripts. Will evolve it to become more of…
require('dotenv').load({'path': '.env'});
var elasticSearch = require("elasticsearch");
var esRWClient = require("./esClient"); //This is es client initialization
var esRClient = require("./esClient_readOnly");
var bunyan = require('bunyan');
var target_index = process.env.target||'reindex'; //Change this to your target index .
var source_index = process.env.source; //Change this to your source index.
var global_scroll_id;