Skip to content

Instantly share code, notes, and snippets.

@saruba
Last active March 29, 2016 11:38
Show Gist options
  • Save saruba/e6d3b3613e0531225fb3 to your computer and use it in GitHub Desktop.
Save saruba/e6d3b3613e0531225fb3 to your computer and use it in GitHub Desktop.
Import all indexes from elasticsearch "http://localhost:9200/_all/_settings,_mapping"
var fs = require('fs');
var querystring = require('querystring');
var http = require('http');
var indexs = JSON.parse(fs.readFileSync('indexes.json', 'utf8'));
var host = '192.168.186.143';
port = '9200',
postData = "",
indexName = "";
for (indexName in indexs) {
postData = JSON.stringify(indexs[indexName]);
console.log('postData', postData);
var options = {
host: host,
port: port,
path: '/' + indexName,
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Content-Length': postData.length
}
}
var req = http.request(options, (res) => {
console.log(`STATUS: ${res.statusCode}`);
console.log(`HEADERS: ${JSON.stringify(res.headers)}`);
res.setEncoding('utf8');
res.on('data', (chunk) => {
console.log(`BODY: ${chunk}`);
});
res.on('end', () => {
console.log('No more data in response.')
})
});
req.on('error', (e) => {
console.log(`problem with request: ${e.message}`);
});
req.write(postData);
req.end();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment