Skip to content

Instantly share code, notes, and snippets.

@paramaggarwal
Created April 3, 2015 04:09
Show Gist options
  • Save paramaggarwal/a1d2e265c70bbf6af7e7 to your computer and use it in GitHub Desktop.
Save paramaggarwal/a1d2e265c70bbf6af7e7 to your computer and use it in GitHub Desktop.
Scrape a few products into Elasticsearch
var elasticsearch = require('elasticsearch');
var es = new elasticsearch.Client();
var superagent = require('superagent');
var async = require('async');
var _ = require('underscore');
es.info(function (err, data) {
if (err) {
return console.error(err);
};
console.log(data);
async.eachLimit(_.range(656604, 657604), 10, indexStyle, function (err) {
if (err) {
return console.error(err);
};
});
});
function indexStyle(styleid, done) {
superagent.get('http://developer.myntra.com/style/' + styleid, function (err, data) {
if (err) {
done();
return console.error(err);
};
es.index({
index: 'demo',
type: 'product',
id: styleid,
body: data.body.data
}, function (err, data) {
if (err) {
done();
return console.error(err);
};
done();
console.log(data);
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment