mirror of
https://github.com/spring-projects/spring-data-elasticsearch.git
synced 2025-07-04 01:32:11 +00:00
DATAES-214 - ElasticsearchTemplate's prepareSearch(Query query) method should use getOffset().
Original PR: #392
This commit is contained in:
parent
8dd7cfcc6e
commit
864d41cb01
@ -143,6 +143,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
|||||||
* @author Peter-Josef Meisch
|
* @author Peter-Josef Meisch
|
||||||
* @author Mathias Teier
|
* @author Mathias Teier
|
||||||
* @author Gyula Attila Csorogi
|
* @author Gyula Attila Csorogi
|
||||||
|
* @author Alexander Shabunevich
|
||||||
*/
|
*/
|
||||||
public class ElasticsearchRestTemplate extends AbstractElasticsearchTemplate
|
public class ElasticsearchRestTemplate extends AbstractElasticsearchTemplate
|
||||||
implements ElasticsearchOperations, EsClient<RestHighLevelClient>, ApplicationContextAware {
|
implements ElasticsearchOperations, EsClient<RestHighLevelClient>, ApplicationContextAware {
|
||||||
@ -1338,7 +1339,13 @@ public class ElasticsearchRestTemplate extends AbstractElasticsearchTemplate
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (query.getPageable().isPaged()) {
|
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.size(query.getPageable().getPageSize());
|
||||||
}
|
}
|
||||||
sourceBuilder.from(startRecord);
|
sourceBuilder.from(startRecord);
|
||||||
|
@ -123,6 +123,7 @@ import org.springframework.util.StringUtils;
|
|||||||
* @author Martin Choraine
|
* @author Martin Choraine
|
||||||
* @author Farid Azaza
|
* @author Farid Azaza
|
||||||
* @author Gyula Attila Csorogi
|
* @author Gyula Attila Csorogi
|
||||||
|
* @author Alexander Shabunevich
|
||||||
*/
|
*/
|
||||||
public class ElasticsearchTemplate extends AbstractElasticsearchTemplate
|
public class ElasticsearchTemplate extends AbstractElasticsearchTemplate
|
||||||
implements ElasticsearchOperations, EsClient<Client>, ApplicationContextAware {
|
implements ElasticsearchOperations, EsClient<Client>, ApplicationContextAware {
|
||||||
@ -1115,7 +1116,13 @@ public class ElasticsearchTemplate extends AbstractElasticsearchTemplate
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (query.getPageable().isPaged()) {
|
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.setSize(query.getPageable().getPageSize());
|
||||||
}
|
}
|
||||||
searchRequestBuilder.setFrom(startRecord);
|
searchRequestBuilder.setFrom(startRecord);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user