title: elastic search scroll limit number of results
body: <p>Please see code below. What I would like to accomplish is to limit the number per batch size (50) but ALSO limit the number of TOTAL results (1000). Using code sample, I however get ALL matching records as a result. What am I doing wrong? Or isn't this supported at all.</p>
  
  <p>Thanks!</p>
  
  <p>Sander</p>
  
  <pre><code>var elasticsearch = require('elasticsearch');
  var _ = require('lodash');
  
  var client = new elasticsearch.Client({
      host: 'host',
      log: 'info'
  });
  
  var allDocuments = [];
  client.search({
      index: "index",
      type: "type",
      scroll: '30s',
      size: 50,
      body: {
          "from": 0,
          "size": 1000,
          "query": {
              "range": {
                  "updated": {
                      "gte": "2016-10-24T08:35:10.540Z",
                      "lte": "2016-10-29T20:35:10.541Z"
                  }
              }
          }
      }
  }, function getMoreUntilDone(error, response) {
      response.hits.hits.forEach(function (hit) {
          allDocuments.push(hit._source);
      });
      if (response.hits.total !== allDocuments.length) {
          client.scroll({
              scrollId: response._scroll_id,
              scroll: '30s'
          }, getMoreUntilDone);
      } else {
          console.log('count', allDocuments.length);
      }
  });
  </code></pre>