mirror of
https://github.com/spring-projects/spring-data-elasticsearch.git
synced 2025-05-29 00:02:10 +00:00
DATAES-1003 - Polishing.
This commit is contained in:
parent
e950752e79
commit
6fd35b56da
@ -1172,9 +1172,9 @@ class RequestFactory {
|
||||
if (StringUtils.hasLength(query.getRoute())) {
|
||||
request.routing(query.getRoute());
|
||||
}
|
||||
|
||||
|
||||
TimeValue timeout = query.getTimeout();
|
||||
if (timeout !=null) {
|
||||
if (timeout != null) {
|
||||
sourceBuilder.timeout(timeout);
|
||||
}
|
||||
|
||||
@ -1252,9 +1252,9 @@ class RequestFactory {
|
||||
if (StringUtils.hasLength(query.getRoute())) {
|
||||
searchRequestBuilder.setRouting(query.getRoute());
|
||||
}
|
||||
|
||||
|
||||
TimeValue timeout = query.getTimeout();
|
||||
if (timeout !=null) {
|
||||
if (timeout != null) {
|
||||
searchRequestBuilder.setTimeout(timeout);
|
||||
}
|
||||
|
||||
|
@ -254,14 +254,20 @@ abstract class AbstractQuery implements Query {
|
||||
public void setScrollTime(@Nullable Duration scrollTime) {
|
||||
this.scrollTime = scrollTime;
|
||||
}
|
||||
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public TimeValue getTimeout() {
|
||||
return timeout;
|
||||
}
|
||||
|
||||
public void setTimeout(TimeValue timeout) {
|
||||
/**
|
||||
* set the query timeout
|
||||
*
|
||||
* @param timeout
|
||||
* @since 4.2
|
||||
*/
|
||||
public void setTimeout(@Nullable TimeValue timeout) {
|
||||
this.timeout = timeout;
|
||||
}
|
||||
}
|
||||
|
@ -198,7 +198,7 @@ public interface Query {
|
||||
|
||||
/**
|
||||
* Sets the {@link HighlightQuery}.
|
||||
*
|
||||
*
|
||||
* @param highlightQuery the query to set
|
||||
* @since 4.0
|
||||
*/
|
||||
@ -216,7 +216,7 @@ public interface Query {
|
||||
* Sets the flag whether to set the Track_total_hits parameter on queries {@see <a href=
|
||||
* "https://www.elastic.co/guide/en/elasticsearch/reference/7.0/search-request-track-total-hits.html">Elasticseacrh
|
||||
* documentation</>}
|
||||
*
|
||||
*
|
||||
* @param trackTotalHits the value to set.
|
||||
* @since 4.0
|
||||
*/
|
||||
@ -235,7 +235,7 @@ public interface Query {
|
||||
|
||||
/**
|
||||
* Sets the maximum value up to which total hits are tracked. Only relevant if #getTrackTotalHits is {@literal null}
|
||||
*
|
||||
*
|
||||
* @param trackTotalHitsUpTo max limit for trackTotalHits
|
||||
* @since 4.1
|
||||
*/
|
||||
@ -253,7 +253,7 @@ public interface Query {
|
||||
/**
|
||||
* For queries that are used in delete request, these are internally handled by Elasticsearch as scroll/bulk delete
|
||||
* queries. Must not return {@literal null} when {@link #hasScrollTime()} returns {@literal true}.
|
||||
*
|
||||
*
|
||||
* @return the scrolltime settings
|
||||
* @since 4.0
|
||||
*/
|
||||
@ -263,7 +263,7 @@ public interface Query {
|
||||
/**
|
||||
* For queries that are used in delete request, these are internally handled by Elasticsearch as scroll/bulk delete
|
||||
* queries.
|
||||
*
|
||||
*
|
||||
* @param scrollTime the scrolltime settings
|
||||
* @since 4.0
|
||||
*/
|
||||
@ -276,11 +276,12 @@ public interface Query {
|
||||
default boolean hasScrollTime() {
|
||||
return getScrollTime() != null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get timeout
|
||||
* Get the query timeout.
|
||||
*
|
||||
* @return null if not set
|
||||
* @since 4.2
|
||||
*/
|
||||
@Nullable
|
||||
TimeValue getTimeout();
|
||||
|
@ -482,22 +482,24 @@ class RequestFactoryTests {
|
||||
|
||||
assertThat(indexRequest.opType()).isEqualTo(DocWriteRequest.OpType.INDEX);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@Test // DATAES-1003
|
||||
@DisplayName("should set timeout to request")
|
||||
void shouldSetTimeoutToRequest() {
|
||||
Query query = new NativeSearchQueryBuilder().withQuery(matchAllQuery()).withTimeout(TimeValue.timeValueSeconds(1)).build();
|
||||
Query query = new NativeSearchQueryBuilder().withQuery(matchAllQuery()).withTimeout(TimeValue.timeValueSeconds(1))
|
||||
.build();
|
||||
|
||||
SearchRequest searchRequest = requestFactory.searchRequest(query, Person.class, IndexCoordinates.of("persons"));
|
||||
|
||||
assertThat(searchRequest.source().timeout()).isEqualTo(TimeValue.timeValueSeconds(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Test // DATAES-1003
|
||||
@DisplayName("should set timeout to requestbuilder")
|
||||
void shouldSetTimeoutToRequestBuilder() {
|
||||
when(client.prepareSearch(any())).thenReturn(new SearchRequestBuilder(client, SearchAction.INSTANCE));
|
||||
Query query = new NativeSearchQueryBuilder().withQuery(matchAllQuery()).withTimeout(TimeValue.timeValueSeconds(1)).build();
|
||||
Query query = new NativeSearchQueryBuilder().withQuery(matchAllQuery()).withTimeout(TimeValue.timeValueSeconds(1))
|
||||
.build();
|
||||
|
||||
SearchRequestBuilder searchRequestBuilder = requestFactory.searchRequestBuilder(client, query, Person.class,
|
||||
IndexCoordinates.of("persons"));
|
||||
@ -505,7 +507,6 @@ class RequestFactoryTests {
|
||||
assertThat(searchRequestBuilder.request().source().timeout()).isEqualTo(TimeValue.timeValueSeconds(1));
|
||||
}
|
||||
|
||||
|
||||
private String requestToString(ToXContent request) throws IOException {
|
||||
return XContentHelper.toXContent(request, XContentType.JSON, true).utf8ToString();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user