0

I am using the elasticsearch client.

var elasticsearch = require('elasticsearch');
   var client = new elasticsearch.Client({
   host:"https://********",
   log: 'trace',
});

I have JSON objects lets say

[{"name":"abc", "age": 23},{"name":"bcd", "age": 25}......]

My Goal to insert it in bulk. I tried but not working.

client.bulk({
    index: "person",
    type: '_doc',
    body: [{JSON}] // input as JSON format

})
Rahul Saini
  • 927
  • 1
  • 11
  • 28
  • Does this answer your question? [NodeJs-ElasticSearch Bulk API error handling](https://stackoverflow.com/questions/37728650/nodejs-elasticsearch-bulk-api-error-handling) – Joe - GMapsBook.com Apr 16 '20 at 12:21

1 Answers1

0

Main thing that need to remember about bulk API, that:

The actions are specified in the request body using a newline delimited JSON (NDJSON) structure.

So it is really important to follow request body formatting, with new lines, action and metadata.

Example:

POST _bulk
{ "index" : { "_index" : "test", "_id" : "1" } }
{ "field1" : "value1" }

Documentation

Alex Baidan
  • 1,065
  • 7
  • 15