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