# Bulk posting to Elasticsearch in Node.js

**URL:** <https://discuss.elastic.co/t/bulk-posting-to-elasticsearch-in-node-js/38100>\
**Category:** Elasticsearch\
**Created:** [December 29, 2015, 11:19am UTC](https://discuss.elastic.co/t/bulk-posting-to-elasticsearch-in-node-js/38100 "2015-12-29T11:19:55Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![pewpewlasers](https://avatars.discourse-cdn.com/v4/letter/p/e274bd/32.png) [@pewpewlasers](https://discuss.elastic.co/u/pewpewlasers)\
**Post date:** [December 29, 2015, 11:19am UTC](https://discuss.elastic.co/t/bulk-posting-to-elasticsearch-in-node-js/38100/1 "2015-12-29T11:19:56Z")

</div>

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 }`

---

<div class="post-metadata">

**Author:** ![jimczi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jimczi/32/47985_2.png) [@jimczi](https://discuss.elastic.co/u/jimczi)\
**Post date:** [December 29, 2015, 6:07pm UTC](https://discuss.elastic.co/t/bulk-posting-to-elasticsearch-in-node-js/38100/2 "2015-12-29T18:07:15Z")

</div>

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](https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/api-reference-1-7.html)

---

<div class="post-metadata">

**Author:** ![pewpewlasers](https://avatars.discourse-cdn.com/v4/letter/p/e274bd/32.png) [@pewpewlasers](https://discuss.elastic.co/u/pewpewlasers)\
**Post date:** [December 30, 2015, 4:44am UTC](https://discuss.elastic.co/t/bulk-posting-to-elasticsearch-in-node-js/38100/3 "2015-12-30T04:44:23Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![pewpewlasers](https://avatars.discourse-cdn.com/v4/letter/p/e274bd/32.png) [@pewpewlasers](https://discuss.elastic.co/u/pewpewlasers)\
**Post date:** [December 31, 2015, 5:13am UTC](https://discuss.elastic.co/t/bulk-posting-to-elasticsearch-in-node-js/38100/4 "2015-12-31T05:13:55Z")

</div>

To clarify things, I am using this package [https://www.npmjs.com/package/request-json](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.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 5, 2017, 11:27pm UTC](https://discuss.elastic.co/t/bulk-posting-to-elasticsearch-in-node-js/38100/5 "2017-07-05T23:27:39Z")

</div>


