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

Scroll api 5.3 throwing error #522

Closed
devarajc opened this issue Apr 4, 2017 · 16 comments
Closed

Scroll api 5.3 throwing error #522

devarajc opened this issue Apr 4, 2017 · 16 comments

Comments

@devarajc
Copy link

devarajc commented Apr 4, 2017

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
}
@andrenarchy
Copy link

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).

@spalger
Copy link
Contributor

spalger commented Apr 5, 2017

Upgrading to 13.0.0-rc1 should fix your issue

@andrenarchy
Copy link

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
}

@spalger
Copy link
Contributor

spalger commented Apr 5, 2017

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

@andrenarchy
Copy link

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.

@spalger
Copy link
Contributor

spalger commented Apr 5, 2017

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

@spalger
Copy link
Contributor

spalger commented Apr 5, 2017

@andrenarchy
Copy link

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"]}.

@andrenarchy
Copy link

andrenarchy commented Apr 5, 2017

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

@spalger
Copy link
Contributor

spalger commented Apr 7, 2017

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

@andrenarchy
Copy link

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();

@sebastian-schmitt
Copy link

sebastian-schmitt commented Apr 11, 2017

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.

@andrenarchy
Copy link

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

@spalger
Copy link
Contributor

spalger commented Apr 25, 2017

@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?

@msiemens
Copy link

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

@kaipi
Copy link

kaipi commented Aug 21, 2017

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

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

6 participants