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
Asked
Active
Viewed 107 times
-1
-
How many documents are we talking? – Val Oct 05 '18 at 11:32
-
all the documents present in index – Rakesh Oct 05 '18 at 11:34
-
In absolute terms, can you provide a count? is it 100, 1000, 10000, 1M, ...? – Val Oct 05 '18 at 11:35
-
100-150, need for my local repository – Rakesh Oct 05 '18 at 11:37
1 Answers
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