File tree Expand file tree Collapse file tree 1 file changed +7
-3
lines changed
src/main/java/org/springframework/data/elasticsearch/repository/query Expand file tree Collapse file tree 1 file changed +7
-3
lines changed Original file line number Diff line number Diff line change 15
15
*/
16
16
package org .springframework .data .elasticsearch .repository .query ;
17
17
18
+ import org .springframework .data .domain .PageRequest ;
18
19
import org .springframework .data .elasticsearch .core .ElasticsearchOperations ;
19
20
import org .springframework .data .elasticsearch .core .mapping .ElasticsearchPersistentProperty ;
20
21
import org .springframework .data .elasticsearch .core .query .CriteriaQuery ;
@@ -49,9 +50,12 @@ public Object execute(Object[] parameters) {
49
50
query .setPageable (accessor .getPageable ());
50
51
return elasticsearchOperations .queryForPage (query , queryMethod .getEntityInformation ().getJavaType ());
51
52
} else if (queryMethod .isCollectionQuery ()) {
52
- if (accessor .getPageable () != null ) {
53
- query .setPageable (accessor .getPageable ());
54
- }
53
+ if (accessor .getPageable () == null ) {
54
+ int itemCount = (int ) elasticsearchOperations .count (query , queryMethod .getEntityInformation ().getJavaType ());
55
+ query .setPageable (new PageRequest (0 , Math .max (1 , itemCount )));
56
+ } else {
57
+ query .setPageable (accessor .getPageable ());
58
+ }
55
59
return elasticsearchOperations .queryForList (query , queryMethod .getEntityInformation ().getJavaType ());
56
60
} else if (tree .isCountProjection ()) {
57
61
return elasticsearchOperations .count (query , queryMethod .getEntityInformation ().getJavaType ());
You can’t perform that action at this time.
0 commit comments