Created
February 20, 2019 09:57
-
-
Save duynguyenhoang/b05c1c6342f639e440422256c68fd040 to your computer and use it in GitHub Desktop.
nodejs + ES
This file contains hidden or 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
| // Demonstrate https://stackoverflow.com/questions/54781538/node-elasticsearch-bulk-index-fails-silently | |
| const elasticsearch = require('elasticsearch'); | |
| const elastic = new elasticsearch.Client({ | |
| host: `localhost:9200` | |
| }); | |
| const inputArray = [ | |
| { | |
| "index": { | |
| "_index": "test-2019.02.19" | |
| } | |
| }, | |
| { | |
| "timestamp": "2019-02-19T02:34:43.526Z", | |
| "data": { | |
| "something": "something" | |
| } | |
| }, | |
| { | |
| "index": { | |
| "_index": "test-2019.02.19" | |
| } | |
| }, | |
| { | |
| "timestamp": "2019-02-19T02:34:43.526Z", | |
| "data": { | |
| "something": "something" | |
| } | |
| } | |
| ]; | |
| const elasticStore = async (inputArray) => { | |
| try { | |
| const insert = await elastic.bulk({ body: inputArray, type: 'test_es'}); | |
| console.log(insert) | |
| } catch (e) { | |
| console.error('failed to insert events into elastic search', {e}); | |
| } | |
| }; | |
| // Test the output | |
| elasticStore(inputArray) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment