DATAES-214 - ElasticsearchTemplate's prepareSearch(Query query) method should use getOffset().

Original PR: #392
This commit is contained in:
Alexander Shabunevich 2020-02-12 22:55:36 +03:00 committed by GitHub
parent 8dd7cfcc6e
commit 864d41cb01
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 2 deletions

View File

@ -143,6 +143,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
* @author Peter-Josef Meisch
* @author Mathias Teier
* @author Gyula Attila Csorogi
* @author Alexander Shabunevich
*/
public class ElasticsearchRestTemplate extends AbstractElasticsearchTemplate
implements ElasticsearchOperations, EsClient<RestHighLevelClient>, ApplicationContextAware {
@ -1338,7 +1339,13 @@ public class ElasticsearchRestTemplate extends AbstractElasticsearchTemplate
}
if (query.getPageable().isPaged()) {
startRecord = query.getPageable().getPageNumber() * query.getPageable().getPageSize();
long offset = query.getPageable().getOffset();
if (offset > Integer.MAX_VALUE) {
throw new IllegalArgumentException(String.format("Offset must not be more than %s", Integer.MAX_VALUE));
}
startRecord = (int) offset;
sourceBuilder.size(query.getPageable().getPageSize());
}
sourceBuilder.from(startRecord);

View File

@ -123,6 +123,7 @@ import org.springframework.util.StringUtils;
* @author Martin Choraine
* @author Farid Azaza
* @author Gyula Attila Csorogi
* @author Alexander Shabunevich
*/
public class ElasticsearchTemplate extends AbstractElasticsearchTemplate
implements ElasticsearchOperations, EsClient<Client>, ApplicationContextAware {
@ -1115,7 +1116,13 @@ public class ElasticsearchTemplate extends AbstractElasticsearchTemplate
}
if (query.getPageable().isPaged()) {
startRecord = query.getPageable().getPageNumber() * query.getPageable().getPageSize();
long offset = query.getPageable().getOffset();
if (offset > Integer.MAX_VALUE) {
throw new IllegalArgumentException(String.format("Offset must not be more than %s", Integer.MAX_VALUE));
}
startRecord = (int) offset;
searchRequestBuilder.setSize(query.getPageable().getPageSize());
}
searchRequestBuilder.setFrom(startRecord);