Elastic Search Repository possibility to get more than 10000 results


I am using ElasticSearchRepository and fetching search results  using SearchQuery.
like below :-

Employee class represents documents of Employee index in ElasticSearch and EmployeeRepository is elasticsearch repository w.r.t Employee index.

NativeSearchQueryBuilder queryBuilder = new NativeSearchQueryBuilder().withPageable(PageRequest.of(0,10));
NativeSearchQuery searchQuery = queryBuilder.withQuery(QueryBuilders.match("dept","biology"));

Page<Employee> employeeResults = employeeRepository.search(searchQuery);

// I am trying to fetch only top 10 records as per pageRequest. But at the same time wanted to know what is the total count matching my criteria
count = employeeResults .getTotalElements();

Employees matching department biology are more than 10k. I always end up with 10k results.

Can I get total count even if it is more than 10k using elasticSearchRepository ?

Please format your code, logs or configuration files using </> icon as explained in this guide and not the citation button. It will make your post more readable.

Or use markdown style like:


This is the icon to use if you are not using markdown format:

There's a live preview panel for exactly this reasons.

Lots of people read these forums, and many of them will simply skip over a post that is difficult to read, because it's just too large an investment of their time to try and follow a wall of badly formatted text.
If your goal is to get an answer to your questions, it's in your interest to make it as easy to read and understand as possible.
Please update your post.

About your question, I don't know how you can solve it with Spring Data which I guess you are using. But here is how you can do it with the Rest Client:

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.