Created
April 3, 2015 04:09
-
-
Save paramaggarwal/a1d2e265c70bbf6af7e7 to your computer and use it in GitHub Desktop.
Scrape a few products into Elasticsearch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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