-1

while creating a rest which function can i use to view all the documents in an index, like for prepareGet takes 3 arguments (indexName, type, id) to view the document, i need to know a function which takes only one argument as indexName and displays all the data in that particular index

Rakesh
  • 11
  • 1
  • 3

1 Answers1

2

If your index only contains a few documents (100-150), then you can get all of them in a single search using the _search endpoint with a size parameter that is bigger than the number of your documents:

GET your-index/_search?size=1000

Using the Java HighLevel REST client, you can do it like this:

SearchRequest searchRequest = new SearchRequest("your-index"); 
SearchSourceBuilder sourceBuilder = new SearchSourceBuilder(); 
searchSourceBuilder.query(QueryBuilders.matchAllQuery()); 
sourceBuilder.from(0); 
sourceBuilder.size(1000); 
searchRequest.source(searchSourceBuilder); 
SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT);
Val
  • 207,596
  • 13
  • 358
  • 360