1
1
/*
2
- * Copyright 2013-2020 the original author or authors.
2
+ * Copyright 2013-2021 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
15
15
*/
16
16
package org .springframework .data .elasticsearch .repository .query ;
17
17
18
- import org .springframework .core .convert .support .GenericConversionService ;
19
18
import org .springframework .data .domain .PageRequest ;
20
19
import org .springframework .data .elasticsearch .core .ElasticsearchOperations ;
21
20
import org .springframework .data .elasticsearch .core .SearchHitSupport ;
22
21
import org .springframework .data .elasticsearch .core .SearchHits ;
23
- import org .springframework .data .elasticsearch .core .convert .DateTimeConverters ;
24
22
import org .springframework .data .elasticsearch .core .mapping .IndexCoordinates ;
25
23
import org .springframework .data .elasticsearch .core .query .StringQuery ;
26
24
import org .springframework .data .elasticsearch .repository .support .StringQueryUtil ;
27
25
import org .springframework .data .repository .query .ParametersParameterAccessor ;
28
26
import org .springframework .data .util .StreamUtils ;
29
27
import org .springframework .util .Assert ;
30
- import org .springframework .util .ClassUtils ;
31
28
32
29
/**
33
30
* ElasticsearchStringQuery
@@ -69,7 +66,12 @@ public Object execute(Object[] parameters) {
69
66
if (queryMethod .isPageQuery ()) {
70
67
stringQuery .setPageable (accessor .getPageable ());
71
68
SearchHits <?> searchHits = elasticsearchOperations .search (stringQuery , clazz , index );
72
- result = SearchHitSupport .page (searchHits , stringQuery .getPageable ());
69
+ if (queryMethod .isSearchPageMethod ()) {
70
+ result = SearchHitSupport .searchPageFor (searchHits , stringQuery .getPageable ());
71
+ } else {
72
+ result = SearchHitSupport
73
+ .unwrapSearchHits (SearchHitSupport .searchPageFor (searchHits , stringQuery .getPageable ()));
74
+ }
73
75
} else if (queryMethod .isStreamQuery ()) {
74
76
if (accessor .getPageable ().isUnpaged ()) {
75
77
stringQuery .setPageable (PageRequest .of (0 , DEFAULT_STREAM_BATCH_SIZE ));
@@ -86,7 +88,9 @@ public Object execute(Object[] parameters) {
86
88
result = elasticsearchOperations .searchOne (stringQuery , clazz , index );
87
89
}
88
90
89
- return queryMethod .isNotSearchHitMethod () ? SearchHitSupport .unwrapSearchHits (result ) : result ;
91
+ return (queryMethod .isNotSearchHitMethod () && !queryMethod .isSearchPageMethod ())
92
+ ? SearchHitSupport .unwrapSearchHits (result )
93
+ : result ;
90
94
}
91
95
92
96
protected StringQuery createQuery (ParametersParameterAccessor parameterAccessor ) {
0 commit comments