11/*
2- * Copyright 2013-2020 the original author or authors.
2+ * Copyright 2013-2021 the original author or authors.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
1515 */
1616package org .springframework .data .elasticsearch .repository .query ;
1717
18- import org .springframework .core .convert .support .GenericConversionService ;
1918import org .springframework .data .domain .PageRequest ;
2019import org .springframework .data .elasticsearch .core .ElasticsearchOperations ;
2120import org .springframework .data .elasticsearch .core .SearchHitSupport ;
2221import org .springframework .data .elasticsearch .core .SearchHits ;
23- import org .springframework .data .elasticsearch .core .convert .DateTimeConverters ;
2422import org .springframework .data .elasticsearch .core .mapping .IndexCoordinates ;
2523import org .springframework .data .elasticsearch .core .query .StringQuery ;
2624import org .springframework .data .elasticsearch .repository .support .StringQueryUtil ;
2725import org .springframework .data .repository .query .ParametersParameterAccessor ;
2826import org .springframework .data .util .StreamUtils ;
2927import org .springframework .util .Assert ;
30- import org .springframework .util .ClassUtils ;
3128
3229/**
3330 * ElasticsearchStringQuery
@@ -69,7 +66,12 @@ public Object execute(Object[] parameters) {
6966 if (queryMethod .isPageQuery ()) {
7067 stringQuery .setPageable (accessor .getPageable ());
7168 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+ }
7375 } else if (queryMethod .isStreamQuery ()) {
7476 if (accessor .getPageable ().isUnpaged ()) {
7577 stringQuery .setPageable (PageRequest .of (0 , DEFAULT_STREAM_BATCH_SIZE ));
@@ -86,7 +88,9 @@ public Object execute(Object[] parameters) {
8688 result = elasticsearchOperations .searchOne (stringQuery , clazz , index );
8789 }
8890
89- return queryMethod .isNotSearchHitMethod () ? SearchHitSupport .unwrapSearchHits (result ) : result ;
91+ return (queryMethod .isNotSearchHitMethod () && !queryMethod .isSearchPageMethod ())
92+ ? SearchHitSupport .unwrapSearchHits (result )
93+ : result ;
9094 }
9195
9296 protected StringQuery createQuery (ParametersParameterAccessor parameterAccessor ) {
0 commit comments