# Elasticsearch with nodejs

**URL:** <https://discuss.elastic.co/t/elasticsearch-with-nodejs/72980>\
**Category:** Elasticsearch\
**Created:** [January 27, 2017, 7:03am UTC](https://discuss.elastic.co/t/elasticsearch-with-nodejs/72980 "2017-01-27T07:03:14Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ramya](https://avatars.discourse-cdn.com/v4/letter/r/e9c0ed/32.png) [@Ramya](https://discuss.elastic.co/u/Ramya)\
**Post date:** [January 27, 2017, 7:03am UTC](https://discuss.elastic.co/t/elasticsearch-with-nodejs/72980/1 "2017-01-27T07:03:14Z")

</div>

I tried to import my json file into elastic search using nodejs  
using bulk method but I got this error  
[2017-01-27 12:24:39,812][DEBUG][action.bulk] [Smuggler II] [logs][3] failed to execute bulk item (index) index {[logs][record][AVnetF6wQ\_w-mHvOpRo5], source[_na_]}  
MapperParsingException[failed to parse]; nested: NotXContentException[Compressor detection can only be called on some xcontent bytes or compressed xcontent bytes];

Here is my code ..help me friends ..thanks in advance  
(function () {  
'use strict';

var fs = require('fs');  
var elasticsearch = require('elasticsearch');  
var esClient = new elasticsearch.Client({  
host: '127.0.0.1:9200',  
log: 'error'  
});

var bulkIndex = function bulkIndex(index, type, data) {  
var bulkBody = [];

```
//data.forEach(item => {
for (var item in data) {
  bulkBody.push({
    index: {
      _index: index,
      _type: type,
      _id: item.id
    }
  });

  bulkBody.push(item);
};

esClient.bulk({body: bulkBody})

.then(response => {
  var errorCount = 0;
  response.items.forEach(item => {
    if (item.index && item.index.error) {
      console.log(++errorCount, item.index.error);
    }
  });
 //console.log(`Successfully indexed ${data.length - errorCount} out of ${data.length} items`);
})
.catch(console.err);

```

};

// only for testing purposes  
// all calls should be initiated through the module  
var test = function test() {  
var articles = JSON.parse(fs.readFileSync('./logstash.json', 'utf8'));  
[//console.log](https://console.log)(`${articles.length} items parsed from data file`);  
bulkIndex('logs', 'record', articles);  
};

test();

/_module.exports = {  
bulkIndex  
};_/  
} ());

---

<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:** [February 24, 2017, 7:03am UTC](https://discuss.elastic.co/t/elasticsearch-with-nodejs/72980/2 "2017-02-24T07:03:47Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
