Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bulk request with empty body throws unhelpful error #245

Closed
GamingCoder opened this issue Jul 29, 2015 · 2 comments
Closed

Bulk request with empty body throws unhelpful error #245

GamingCoder opened this issue Jul 29, 2015 · 2 comments

Comments

@GamingCoder
Copy link

I came across this error in a script to automatically delete old entries. When no entries have to be deleted the script tried to do a bulk request with an empty array as body.

I created this script to show the error

var elasticsearch = require('elasticsearch');
var client = new elasticsearch.Client({
    host: 'localhost:9200',
    log: 'trace'
});
client.bulk({
    "body": []
}, function(err, resp) {
    if (err){
        console.trace(err);
    } else {
        console.log(resp);
    }
});

When running this script you get the following console output

Elasticsearch INFO: 2015-07-29T15:40:47Z
  Adding connection to http://localhost:9200/

Elasticsearch DEBUG: 2015-07-29T15:40:47Z
  starting request { method: 'POST',
    bulkBody: true,
    path: '/_bulk',
    body: [],
    query: {} }


Elasticsearch TRACE: 2015-07-29T15:40:47Z
  -> POST http://localhost:9200/_bulk

  <- 400
  {
    "error": "ElasticsearchParseException[Failed to derive xcontent from org.elasticsearch.common.bytes.BytesArray@1]",
    "status": 400
  }

Elasticsearch DEBUG: 2015-07-29T15:40:47Z
  Request complete

Trace: { [Error: ElasticsearchParseException[Failed to derive xcontent from org.elasticsearch.common.bytes.BytesArray@1]]
  status: '400',
  message: 'ElasticsearchParseException[Failed to derive xcontent from org.elasticsearch.common.bytes.BytesArray@1]' }
    at /tmp/tmp.fK3wh7WwBt/index.js:10:17
    at respond (/tmp/tmp.fK3wh7WwBt/node_modules/elasticsearch/src/lib/transport.js:251:9)
    at checkRespForFailure (/tmp/tmp.fK3wh7WwBt/node_modules/elasticsearch/src/lib/transport.js:200:7)
    at HttpConnector.<anonymous> (/tmp/tmp.fK3wh7WwBt/node_modules/elasticsearch/src/lib/connectors/http.js:155:7)
    at IncomingMessage.wrapper (/tmp/tmp.fK3wh7WwBt/node_modules/elasticsearch/node_modules/lodash/index.js:3095:19)
    at IncomingMessage.emit (events.js:117:20)
    at _stream_readable.js:943:16
    at process._tickCallback (node.js:419:13)

I run

  • node v0.10.32
  • ES client 5.0.0
  • ES 1.6.0
@alanning
Copy link

A more descriptive error message would be nice. Perhaps something like, "Malformed body".

I just ran across this when the body field value was invalid:

EsClient.index({
      index: config.index,
      type: config.type,
      id: doc._id,
      body: doc  // <= ["xyz", {profile: {...}}]
    });
  • ES 1.6.0
  • npm javascript api v10.1.2

@spalger
Copy link
Contributor

spalger commented Jan 21, 2016

I agree, the error is not very clear about the actual problem and it is really unclear how to fix it. This error is not generated by elasticsearch-js though, it is sent from elasticsearch and provided to the user directly.

I suggest asking elasticsearch to provide a more informative error message.

@spalger spalger closed this as completed Jan 21, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants