-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathelastic-writer.js
51 lines (38 loc) · 1.08 KB
/
elastic-writer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
var elasticsearch = require('elasticsearch');
var fs = require('fs');
var JSONStream = require('JSONStream');
var sentiment = require('sentiment');
var stream = fs.createReadStream('data/backup/stocktwits_messages_jan_2016.json', {
encoding: 'utf8'
});
var log4js = require('log4js');
var logger = log4js.getLogger('ES-WRITER');
logger.setLevel('INFO');
var parser = JSONStream.parse();
var client = new elasticsearch.Client({
host: 'localhost:9200'
});
stream.pipe(parser);
parser.on('data', function(obj) {
logger.info("Reading...");
var customSentiment = sentiment(obj.body);
var newObj = {
obj: obj,
customSentiment: customSentiment
}
processLine(newObj);
});
function processLine(line) { // here's where we do something with a line
logger.info("Processing...");
client.create({
requestTimeout: 1000000000000,
index: 'test123',
type: 'block',
body: line
}, function(error, response) {
if (error) {
logger.error(error);
}
});
logger.info("Record Created...");
}