2

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 1

2

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.

Sign up to request clarification or add additional context in comments.

5 Comments

what is repository.count() here?
Will give you count of documents in index for that repository
The code written in answer is using spring data elastic search We create repositories for indices when we use spring data
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.
@Verv Could you please elaborate your solution more. ElasticSearchTemplate does not take pageRequest as argeument.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.