mirror of
https://github.com/spring-projects/spring-data-elasticsearch.git
synced 2025-06-12 07:02:10 +00:00
DATAES-115 Add count before projection query to retrieve all results.
This commit is contained in:
parent
d92137247f
commit
cf3c4f7c06
@ -15,6 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.elasticsearch.repository.query;
|
||||
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
|
||||
import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentProperty;
|
||||
import org.springframework.data.elasticsearch.core.query.CriteriaQuery;
|
||||
@ -49,9 +50,12 @@ public class ElasticsearchPartQuery extends AbstractElasticsearchRepositoryQuery
|
||||
query.setPageable(accessor.getPageable());
|
||||
return elasticsearchOperations.queryForPage(query, queryMethod.getEntityInformation().getJavaType());
|
||||
} else if (queryMethod.isCollectionQuery()) {
|
||||
if (accessor.getPageable() != null) {
|
||||
query.setPageable(accessor.getPageable());
|
||||
}
|
||||
if (accessor.getPageable() == null) {
|
||||
int itemCount = (int) elasticsearchOperations.count(query, queryMethod.getEntityInformation().getJavaType());
|
||||
query.setPageable(new PageRequest(0, Math.max(1, itemCount)));
|
||||
} else {
|
||||
query.setPageable(accessor.getPageable());
|
||||
}
|
||||
return elasticsearchOperations.queryForList(query, queryMethod.getEntityInformation().getJavaType());
|
||||
} else if (tree.isCountProjection()) {
|
||||
return elasticsearchOperations.count(query, queryMethod.getEntityInformation().getJavaType());
|
||||
|
Loading…
x
Reference in New Issue
Block a user