title: Elasticsearch not able to fetch more than 10 documents using Java API Query
body: <p>Am reading file path from one index named as <code>documents</code> from that filepath and reading the file and indexing those file contents in another index named as <code>documents_attachment</code> using java code.</p>
  
  <p>so, during the first process, am not able to fetch more than <code>10</code> records  at a time, Its giving only <code>10</code> records from 
  the <code>document</code> index. I have more than <code>100000</code> records in my <code>doucment</code> index.</p>
  
  <p>How can i fetch all the <code>100000</code> records at a time.</p>
  
  <p>I have tried with <code>searchSourceBuilder.size(10000);</code> then its indexing till <code>10K</code> records not more than that, and this method not allowing me to give more than <code>10000</code> as size.</p>
  
  <p>Please find my below java code that am using.</p>
  
  <pre><code>public class DocumentIndex {
  
  private final static String INDEX = "documents";  
  private final static String ATTACHMENT = "document_attachment"; 
  private final static String TYPE = "doc";
  private static final Logger logger = Logger.getLogger(Thread.currentThread().getStackTrace()[0].getClassName());
  
  public static void main(String args[]) throws IOException {
  
  
      RestHighLevelClient restHighLevelClient = null;
      Document doc=new Document();
  
      logger.info("Started Indexing the Document.....");
  
      try {
          restHighLevelClient = new RestHighLevelClient(RestClient.builder(new HttpHost("localhost", 9200, "http"),
                  new HttpHost("localhost", 9201, "http")));
      } catch (Exception e) {
          System.out.println(e.getMessage());
      }
  
  
      //Fetching Id, FilePath &amp; FileName from Document Index. 
      SearchRequest searchRequest = new SearchRequest(INDEX); 
      searchRequest.types(TYPE);
      SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
      QueryBuilder qb = QueryBuilders.matchAllQuery();
      searchSourceBuilder.query(qb);
      //searchSourceBuilder.size(10000); 
      searchRequest.source(searchSourceBuilder);
      SearchResponse searchResponse = null;
      try {
           searchResponse = restHighLevelClient.search(searchRequest);
      } catch (IOException e) {
          e.getLocalizedMessage();
      }
  
      SearchHit[] searchHits = searchResponse.getHits().getHits();
      long totalHits=searchResponse.getHits().totalHits;
      logger.info("Total Hits ---&gt;"+totalHits);
  
  
      File all_files_path = new File("d:\\All_Files_Path.txt");
      File available_files = new File("d:\\Available_Files.txt");
      File missing_files = new File("d:\\Missing_Files.txt");
      all_files_path.deleteOnExit();
      available_files.deleteOnExit();
      missing_files.deleteOnExit();
      all_files_path.createNewFile();
      available_files.createNewFile();
      missing_files.createNewFile();
  
      int totalFilePath=1;
      int totalAvailableFile=1;
      int missingFilecount=1;
  
      Map&lt;String, Object&gt; jsonMap ;
      for (SearchHit hit : searchHits) {
  
          String encodedfile = null;
          File file=null;
  
          Map&lt;String, Object&gt; sourceAsMap = hit.getSourceAsMap();
  
  
          if(sourceAsMap != null) {  
              doc.setId((int) sourceAsMap.get("id"));
              doc.setApp_language(String.valueOf(sourceAsMap.get("app_language")));
          }
  
          String filepath=doc.getPath().concat(doc.getFilename());
  
  
  
          try(PrintWriter out = new PrintWriter(new FileOutputStream(all_files_path, true))  ){
              out.println("FilePath Count ---"+totalFilePath+":::::::ID---&gt; "+doc.getId()+"File Path ---&gt;"+filepath);
          }
  
          file = new File(filepath);
          if(file.exists() &amp;&amp; !file.isDirectory()) {
              try {
                    try(PrintWriter out = new PrintWriter(new FileOutputStream(available_files, true))  ){
                          out.println("Available File Count ---&gt;"+totalAvailableFile+":::::::ID---&gt; "+doc.getId()+"File Path ---&gt;"+filepath);
                          totalAvailableFile++;
                      }
                  FileInputStream fileInputStreamReader = new FileInputStream(file);
                  byte[] bytes = new byte[(int) file.length()];
                  fileInputStreamReader.read(bytes);
                  encodedfile = new String(Base64.getEncoder().encodeToString(bytes));
                  fileInputStreamReader.close();
              } catch (FileNotFoundException e) {
                  e.printStackTrace();
              }
          }
          else
          {
              PrintWriter out = new PrintWriter(new FileOutputStream(missing_files, true));
              out.close();
              missingFilecount++;
          }
  
          jsonMap = new HashMap&lt;&gt;();
          jsonMap.put("id", doc.getId());
          jsonMap.put("app_language", doc.getApp_language());
          jsonMap.put("fileContent", encodedfile);
  
          String id=Long.toString(doc.getId());
  
          IndexRequest request = new IndexRequest(ATTACHMENT, "doc", id )
                  .source(jsonMap)
                  .setPipeline(ATTACHMENT);
  
          PrintStream printStream = new PrintStream(new File("d:\\exception.txt"));
          try {
              IndexResponse response = restHighLevelClient.index(request);
  
          } catch(ElasticsearchException e) {
              if (e.status() == RestStatus.CONFLICT) {
              }
              e.printStackTrace(printStream);
          }
  
          totalFilePath++;
  
  
      }
  
      logger.info("Indexing done.....");
  }
  </code></pre>
  
  <p>}</p>