title: Getting all records from Elasticsearch using Java API
body: <p>I am trying to get all the records from Elasticsearch using Java API. But I receive the below error</p>
  
  <blockquote>
    <p>n[[Wild Thing][localhost:9300][indices:data/read/search[phase/dfs]]];
    nested: QueryPhaseExecutionException[Result window is too large, from
    + size must be less than or equal to: [10000] but was [10101].</p>
  </blockquote>
  
  <p>My code is as below</p>
  
  <pre><code>Client client;
  try {
      client = TransportClient.builder().build().
              addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("localhost"), 9300));
      int from = 1;
      int to = 100;
      while (from &lt;= 131881) {
          SearchResponse response = client
                  .prepareSearch("demo_risk_data")
                  .setSearchType(SearchType.DFS_QUERY_THEN_FETCH).setFrom(from)
                  .setQuery(QueryBuilders.boolQuery().mustNot(QueryBuilders.termQuery("user_agent", "")))
                  .setSize(to).setExplain(true).execute().actionGet();
          if (response.getHits().getHits().length &gt; 0) {
              for (SearchHit searchData : response.getHits().getHits()) {
                  JSONObject value = new JSONObject(searchData.getSource());
                  System.out.println(value.toString());
              }
          }
      }
  }
  </code></pre>
  
  <p>Total number of records currently present are 131881 ,so I start with <code>from = 1</code> and <code>to = 100</code> and then get 100 records until <code>from &lt;= 131881</code>. Is there are way where I can check get records in set of say 100 until there are no further records in Elasticsearch.</p>