Skip to content

Instantly share code, notes, and snippets.

@duynguyenhoang
Created February 20, 2019 09:57
Show Gist options
  • Select an option

  • Save duynguyenhoang/b05c1c6342f639e440422256c68fd040 to your computer and use it in GitHub Desktop.

Select an option

Save duynguyenhoang/b05c1c6342f639e440422256c68fd040 to your computer and use it in GitHub Desktop.
nodejs + ES
// 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