Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ```
- async function writeTheEventCollectionToElasticsearch(theEventCollection, eventName) {
- console.log("Found theEventCollection = " + theEventCollection.length);
- if (theEventCollection.length > 0) {
- var bulkData = {};
- var theBodyArray = [];
- theEventCollection.forEach(function(obj) {
- eventHash = web3.utils.sha3(obj.transactionHash, obj.logIndex);
- theId = {};
- actionDescription = {};
- theId["_id"] = eventHash;
- theId["_type"] = "event";
- theId["_index"] = 'events';
- actionDescription["index"] = theId;
- theBodyArray.push(actionDescription);
- theDocumentToIndex = {};
- theDocumentToIndex["name"] = eventName;
- theDocumentToIndex["jsonEventObject"] = obj;
- theBodyArray.push(theDocumentToIndex);
- });
- if (theBodyArray.length > 0) {
- bulkData["body"] = theBodyArray;
- console.log("Adding the following data to the events")
- console.log(JSON.stringify(bulkData));
- bulkIngest(bulkData);
- }
- }
- }
- function bulkIngest(bulkData) {
- client.bulk(bulkData, function(error, response) {
- if (error) {
- console.error(error);
- return;
- } else {
- console.log(response);
- }
- });
- }
- ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement