Advertisement
Guest User

Untitled

a guest
Mar 18th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. ```
  2. async function writeTheEventCollectionToElasticsearch(theEventCollection, eventName) {
  3. console.log("Found theEventCollection = " + theEventCollection.length);
  4. if (theEventCollection.length > 0) {
  5. var bulkData = {};
  6. var theBodyArray = [];
  7. theEventCollection.forEach(function(obj) {
  8. eventHash = web3.utils.sha3(obj.transactionHash, obj.logIndex);
  9. theId = {};
  10. actionDescription = {};
  11. theId["_id"] = eventHash;
  12. theId["_type"] = "event";
  13. theId["_index"] = 'events';
  14. actionDescription["index"] = theId;
  15. theBodyArray.push(actionDescription);
  16. theDocumentToIndex = {};
  17. theDocumentToIndex["name"] = eventName;
  18. theDocumentToIndex["jsonEventObject"] = obj;
  19. theBodyArray.push(theDocumentToIndex);
  20. });
  21. if (theBodyArray.length > 0) {
  22. bulkData["body"] = theBodyArray;
  23. console.log("Adding the following data to the events")
  24. console.log(JSON.stringify(bulkData));
  25. bulkIngest(bulkData);
  26. }
  27. }
  28. }
  29.  
  30. function bulkIngest(bulkData) {
  31. client.bulk(bulkData, function(error, response) {
  32. if (error) {
  33. console.error(error);
  34. return;
  35. } else {
  36. console.log(response);
  37. }
  38. });
  39.  
  40. }
  41. ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement