I want to read all the documents from my es index. So i using the following function for that:
public List<Map<String, Object>> getAllDocs(){
System.out.println(indexName+typeName);
SearchResponse response = client.prepareSearch(indexName)
.setTypes(typeName)
.setQuery(QueryBuilders.matchAllQuery())
.execute()
.actionGet();
for(SearchHit hit : response.getHits()){
//System.out.println("id:"+hit.getId()+" row:"+hit.getSource());
esData.add(hit.getSource());
}
return esData;
}
But this function only returning 10 documents. If i add one more parameter .setSize(100)
then it will return 100 documents. How can i get all the documents in an index without .setSize(100) parameter?
Not really an effective way of doing this, probably because this could be a real performance problem. If you need all records there are at least two ways of doing this:
Using pagination: size and from
Using the scroll api: http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-request-scroll.html
Another way could be to set a higher size, first do a count query to obtain the count of all items than set the size to this value. But I would never use this solution in production.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With