I have many documents on my elasticsearch. I am using elasticsearchTemplate.queryForList(SearchQuery, class) to get the documents depending on my query. This query always return 10 documents. Does elasticsearch provide any api where all the documents that match the query will be returned?
1 Answer
You need to add Page Request in your searchQuery.
NativeSearchQueryBuilder builder = new NativeSearchQueryBuilder().withQuery(matchAllQuery()).withPageable(new PageRequest(0, repository.count() as int))
SearchQuery query = builder.build()
Repository.count() will give the count of documents in your index.
Hope this helps.
5 Comments
Mohammad Saifullah
what is repository.count() here?
Richa
Will give you count of documents in index for that repository
Richa
The code written in answer is using spring data elastic search We create repositories for indices when we use spring data
Verv
For anyone coming across this in 2018 like me,
new PageRequest(0, repository.count() is deprecated and you may use PageRequest.of(0, repository.count() instead.vkg
@Verv Could you please elaborate your solution more. ElasticSearchTemplate does not take pageRequest as argeument.