Bulk posting to Elasticsearch in Node.js


#1

I am using request.js to post data to the elasticsearch server. Indexing single document is working however I am not able to make bulk work.

I have a simple function that posts data to "localhost:9200/_bulk"

with var client setup already I use:

client.post('_bulk', data, function(err, res, body) {
     console.log(err);
     console.log(body);
     back({
          success: 1
     });
});

And the data is created by stringifying objects for example:

data = JSON.stringify( {update:{_index:"myindex", _type:"users", _id: 23}} ) + "\n" + JSON.stringify( {doc: { blocked: 1 }} ) + "\n";

Using this I get an error:

{ error: 'ActionRequestValidationException[Validation Failed: 1: no requests added;]', status: 400 }


(Jimferenczi) #2

You're not using the API correctly. This page explains how to use the bulk indexing properly with js:
https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/api-reference-1-7.html


#3

I am not using the elasticsearch js api. I am instead trying to make this work with normal post call.


#4

To clarify things, I am using this package https://www.npmjs.com/package/request-json
When I index a single document or update it is working fine. The error is only for bulk feature.


(system) #5