question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

bulk insert not working - newline separated JSON body not working

See original GitHub issue

🐛 Bug Report

Cannot insert newline separate JSON

To Reproduce

  const v = lst.map(v => JSON.stringify({doc: v.value})).join('\n') + '\n';

  client.bulk({
    index: 'foo',
    body: v
  })
   .catch(e => {
     log.error(e);
   });

I get this error:

      ResponseError: illegal_argument_exception
      at IncomingMessage.<anonymous> (/Users/alex/codes/interos/@interos/elastic-search/node_modules/@elastic/elasticsearch/lib/Transport.js:287:25)
      at IncomingMessage.emit (events.js:208:15)
      at endReadableNT (_stream_readable.js:1154:12)
      at processTicksAndRejections (internal/process/task_queues.js:77:11)

Why doesn’t the stack trace give me more to work with btw? ResponseError: illegal_argument_exception with no further information does not give me much to work with 😦

Your Environment

This however does work fine:

  client.index({
      index: 'foo',
      body: {
        doc: v.value
      }
    })
     .catch(e => {
       log.error(e);
     });

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
delvedorcommented, Sep 11, 2019

What is log in your code?

Take this example to reproduce the error:

'use strict'

const { Client } = require('@elastic/elasticsearch')
const client = new Client({ node: 'http://localhost:9200' })

client.indices.create({
  index: 'test',
  body: {
    mappings: {
      properties: {
        foo: { type: 'integer' }
      }
    }
  }
}, { ignore: [400] }, (err, result) => {
  if (err) return console.log(err)
  client.index({
    index: 'test',
    body: { foo: 'bar' }
  }, (err, result) => {
    if (err) return console.log(err)
  })
})

The code above produces the following log on Node.js v12:

ResponseError: mapper_parsing_exception
    at IncomingMessage.<anonymous> (.../elasticsearch-js/lib/Transport.js:287:25)
    at IncomingMessage.emit (events.js:201:15)
    at endReadableNT (_stream_readable.js:1130:12)
    at processTicksAndRejections (internal/process/task_queues.js:84:9) {
  name: 'ResponseError',
  meta: {
    body: { error: [Object], status: 400 },
    statusCode: 400,
    headers: {
      'content-type': 'application/json; charset=UTF-8',
      'content-length': '459'
    },
    warnings: null,
    meta: {
      context: null,
      request: [Object],
      name: 'elasticsearch-js',
      connection: [Object],
      attempts: 0,
      aborted: false
    }
  }
}

As you can see, the full error object is logged and the properties are there. I think you are using a custom logger that does not know how to serialize the Error objects, and by default, it logs only the error message and stacktrace.

1reaction
delvedorcommented, Sep 10, 2019

Hello! If you inspect the error object you should be able to see many other fields. Unfortunately, they are not well documented in the docs, I’ll take care of this. In the meantime, you can find the error classes here: https://github.com/elastic/elasticsearch-js/blob/f7be49f2bafa3b9ddc90b0caac5b70932e6db35b/lib/errors.js#L71-L94

Regarding the bulk body, I think you are not creating the body correctly. I would suggest you take a look at this example 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

NewLine error in Elasticsearch bulk API post request
I am using elasticsearch service on AWS through a lambda function and trying to post this data using aws NodeHttpClient. Not sure how...
Read more >
Loading line-delimited JSON files in SQL Server 2016
Loading Line-Delimited JSON files in SQL Server. One of the problem with JSON is the fact that you cannot continuously append JSON messages....
Read more >
How to handle newlines in JSON
First, we need to declare a variable as “json1” and then we need to assign the JSON to it. · In JSON object...
Read more >
Bulk API | Elasticsearch Guide [8.5]
The request body contains a newline-delimited list of create , delete , index , and update actions and their associated source data.
Read more >
Create issues using the CSV importer | Jira Work ...
Tips for importing CSV data into issue fields ; Comment Body. You can import issues with multiple comments by entering each comment in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found