Elasticsearch-js: Scroll api 5.3 throwing error

Created on 4 Apr 2017  路  16Comments  路  Source: elastic/elasticsearch-js

var allTitles = [];
var i =0;

var elasticsearch = require('elasticsearch');

var client = new elasticsearch.Client({
    host: 'localhost:9200',
 });
// first we do a search, and specify a scroll timeout
client.search({
  index: 'movies',
  scroll: '30s', 
  size:1,
  _source : 'title'
}, function getMoreUntilDone(error, response) {
  // collect the title from each response

  console.log('i',i++);


  console.log(JSON.stringify(response));

  response.hits.hits.forEach(function (hit) {
    allTitles.push(hit._source.title);
  });
  if (response.hits.total > allTitles.length) {
    // ask elasticsearch for the next set of hits from this search
    client.scroll({
       scrollId: response._scroll_id,
        scroll: '30s', 
    }, getMoreUntilDone);
  } else {
    console.log('every "test" title', allTitles);
  }
});

when I running the code throwing error

{
  "error": {
    "root_cause": [
      {
        "type": "illegal_argument_exception",
        "reason": "Failed to parse request body"
      }
    ],
    "type": "illegal_argument_exception",
    "reason": "Failed to parse request body",
    "caused_by": {
      "type": "json_parse_exception",
      "reason": "Unrecognized token 'DnF1ZXJ5VGhlbkZldGNoBQAAAAAAAAHKFnV6a2NabEh4VDZLQmdzUzY0Y2tpd0EAAAAAAAAByxZ1emtjWmxIeFQ2S0Jnc1M2NGNraXdBAAAAAAAAAcwWdXprY1psSHhUNktCZ3NTNjRja2l3QQAAAAAAAAHOFnV6a2NabEh4VDZLQmdzUzY0Y2tpd0EAAAAAAAABzRZ1emtjWmxIeFQ2S0Jnc1M2NGNraXdB': was expecting ('true', 'false' or 'null')\n at [Source: org.elasticsearch.transport.netty4.ByteBufStreamInput@67ba4d99; line: 1, column: 457]"
    }
  },
  "status": 400
}
bug pending release

Most helpful comment

Upgrading to 13.0.0-rc1 should fix your issue

All 16 comments

Same here. Just checked with wireshark that the HTTP request to elasticsearch contains the scroll parameter in the URL and the body is the plain token instead of JSON of the form {"scroll_id": "X"} (even though the content type header indicates application/json).

Upgrading to 13.0.0-rc1 should fix your issue

Thanks! This fixed the issue with scroll but clearScroll now throws the following:

{
  "error": {
    "root_cause": [
      {
        "type": "illegal_argument_exception",
        "reason": "Unknown parameter [scroll_id] in request body or parameter is of the wrong type[VALUE_STRING] "
      }
    ],
    "type": "illegal_argument_exception",
    "reason": "Unknown parameter [scroll_id] in request body or parameter is of the wrong type[VALUE_STRING] "
  },
  "status": 400
}

What version of elasticsearch are you using? The es docs describe that as the required body parameter here: https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-scroll.html

Elasticsearch 5.3, elasticsearchjs 13.0.0-rc1. The HTTP request to elasticsearch has the scroll parameter in the URL (_search/scroll/SCROLLID) and the body as JSON.

Oh... that's unexpected. Good catch!

Thanks, seems like our unit tests do a good job. 馃槈

Unfortunately, this still gives the above error message (Unknown parameter [scroll_id] in request body or parameter is of the wrong type[VALUE_STRING]). The scroll id is not in the URL anymore and the body is of the form {"scroll_id": "X"}. In the docs you linked it looks like it should be {"scroll_id": ["X"]}.

Just to confirm: passing an array for the scrollId parameter fixes the issue. But according to the docs it should also accept a string.

@andrenarchy can you share a reproduction script? That absolutely shouldn't be the case...

Sure, the following script fails:

const elasticsearch = require('elasticsearch');

async function search() {
  const client = new elasticsearch.Client({});

  const result = await client.search({
    index: 'documentrevisions',
    size: 1,
    scroll: '10m',
  });

  // the next line fails with the above error
  const clear = await client.clearScroll({scrollId: result._scroll_id});
  // this one works:
  // const clear = await client.clearScroll({scrollId: [result._scroll_id]});
}

search();

you have to change this mapping here and this mapping here to this:

params: {scrollId: {type: 'String'}}

and everything should be working.

(i. e. transmit a Json-Object as the request body that has the key scrollId mapped to the actual scrollId instead of transmitting the scrollId itself as a Json/String value)

I linked the 5.5-api-file, but the corresponding files of the other versions should be the same - just watch out to edit the file you are referring to when setting up the client.

Why exactly was this closed? The issue I described above for clearScroll persists in 13.0.0.

@andrenarchy I consider this issue closed because the original issue is fixed. Could you please summarize the issue you're seeing in a new issue?

Can confirm this issue with ElasticSearch v5.4.0 and elasticsearch-js v13.3.1, getting the same error message.

This is still valid issue, still not working with elastic 5.5 and elasticsearch.js v13.3.1

Was this page helpful?
0 / 5 - 0 ratings

Related issues

matiasdecarli picture matiasdecarli  路  10Comments

NassiHarel picture NassiHarel  路  10Comments

milu2003 picture milu2003  路  17Comments

villasv picture villasv  路  15Comments

Remexllee picture Remexllee  路  9Comments