Skip to content

Commit 6fd35b5

Browse files
committed
DATAES-1003 - Polishing.
1 parent e950752 commit 6fd35b5

File tree

4 files changed

+27
-19
lines changed

4 files changed

+27
-19
lines changed

Diff for: src/main/java/org/springframework/data/elasticsearch/core/RequestFactory.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -1172,9 +1172,9 @@ private SearchRequest prepareSearchRequest(Query query, @Nullable Class<?> clazz
11721172
if (StringUtils.hasLength(query.getRoute())) {
11731173
request.routing(query.getRoute());
11741174
}
1175-
1175+
11761176
TimeValue timeout = query.getTimeout();
1177-
if (timeout !=null) {
1177+
if (timeout != null) {
11781178
sourceBuilder.timeout(timeout);
11791179
}
11801180

@@ -1252,9 +1252,9 @@ private SearchRequestBuilder prepareSearchRequestBuilder(Query query, Client cli
12521252
if (StringUtils.hasLength(query.getRoute())) {
12531253
searchRequestBuilder.setRouting(query.getRoute());
12541254
}
1255-
1255+
12561256
TimeValue timeout = query.getTimeout();
1257-
if (timeout !=null) {
1257+
if (timeout != null) {
12581258
searchRequestBuilder.setTimeout(timeout);
12591259
}
12601260

Diff for: src/main/java/org/springframework/data/elasticsearch/core/query/AbstractQuery.java

+8-2
Original file line numberDiff line numberDiff line change
@@ -254,14 +254,20 @@ public Duration getScrollTime() {
254254
public void setScrollTime(@Nullable Duration scrollTime) {
255255
this.scrollTime = scrollTime;
256256
}
257-
257+
258258
@Nullable
259259
@Override
260260
public TimeValue getTimeout() {
261261
return timeout;
262262
}
263263

264-
public void setTimeout(TimeValue timeout) {
264+
/**
265+
* set the query timeout
266+
*
267+
* @param timeout
268+
* @since 4.2
269+
*/
270+
public void setTimeout(@Nullable TimeValue timeout) {
265271
this.timeout = timeout;
266272
}
267273
}

Diff for: src/main/java/org/springframework/data/elasticsearch/core/query/Query.java

+8-7
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ default Integer getMaxResults() {
198198

199199
/**
200200
* Sets the {@link HighlightQuery}.
201-
*
201+
*
202202
* @param highlightQuery the query to set
203203
* @since 4.0
204204
*/
@@ -216,7 +216,7 @@ default Optional<HighlightQuery> getHighlightQuery() {
216216
* Sets the flag whether to set the Track_total_hits parameter on queries {@see <a href=
217217
* "https://www.elastic.co/guide/en/elasticsearch/reference/7.0/search-request-track-total-hits.html">Elasticseacrh
218218
* documentation</>}
219-
*
219+
*
220220
* @param trackTotalHits the value to set.
221221
* @since 4.0
222222
*/
@@ -235,7 +235,7 @@ default Optional<HighlightQuery> getHighlightQuery() {
235235

236236
/**
237237
* Sets the maximum value up to which total hits are tracked. Only relevant if #getTrackTotalHits is {@literal null}
238-
*
238+
*
239239
* @param trackTotalHitsUpTo max limit for trackTotalHits
240240
* @since 4.1
241241
*/
@@ -253,7 +253,7 @@ default Optional<HighlightQuery> getHighlightQuery() {
253253
/**
254254
* For queries that are used in delete request, these are internally handled by Elasticsearch as scroll/bulk delete
255255
* queries. Must not return {@literal null} when {@link #hasScrollTime()} returns {@literal true}.
256-
*
256+
*
257257
* @return the scrolltime settings
258258
* @since 4.0
259259
*/
@@ -263,7 +263,7 @@ default Optional<HighlightQuery> getHighlightQuery() {
263263
/**
264264
* For queries that are used in delete request, these are internally handled by Elasticsearch as scroll/bulk delete
265265
* queries.
266-
*
266+
*
267267
* @param scrollTime the scrolltime settings
268268
* @since 4.0
269269
*/
@@ -276,11 +276,12 @@ default Optional<HighlightQuery> getHighlightQuery() {
276276
default boolean hasScrollTime() {
277277
return getScrollTime() != null;
278278
}
279-
279+
280280
/**
281-
* Get timeout
281+
* Get the query timeout.
282282
*
283283
* @return null if not set
284+
* @since 4.2
284285
*/
285286
@Nullable
286287
TimeValue getTimeout();

Diff for: src/test/java/org/springframework/data/elasticsearch/core/RequestFactoryTests.java

+7-6
Original file line numberDiff line numberDiff line change
@@ -482,30 +482,31 @@ void shouldSetOpTypeIndexIfSpecified() {
482482

483483
assertThat(indexRequest.opType()).isEqualTo(DocWriteRequest.OpType.INDEX);
484484
}
485-
486-
@Test
485+
486+
@Test // DATAES-1003
487487
@DisplayName("should set timeout to request")
488488
void shouldSetTimeoutToRequest() {
489-
Query query = new NativeSearchQueryBuilder().withQuery(matchAllQuery()).withTimeout(TimeValue.timeValueSeconds(1)).build();
489+
Query query = new NativeSearchQueryBuilder().withQuery(matchAllQuery()).withTimeout(TimeValue.timeValueSeconds(1))
490+
.build();
490491

491492
SearchRequest searchRequest = requestFactory.searchRequest(query, Person.class, IndexCoordinates.of("persons"));
492493

493494
assertThat(searchRequest.source().timeout()).isEqualTo(TimeValue.timeValueSeconds(1));
494495
}
495496

496-
@Test
497+
@Test // DATAES-1003
497498
@DisplayName("should set timeout to requestbuilder")
498499
void shouldSetTimeoutToRequestBuilder() {
499500
when(client.prepareSearch(any())).thenReturn(new SearchRequestBuilder(client, SearchAction.INSTANCE));
500-
Query query = new NativeSearchQueryBuilder().withQuery(matchAllQuery()).withTimeout(TimeValue.timeValueSeconds(1)).build();
501+
Query query = new NativeSearchQueryBuilder().withQuery(matchAllQuery()).withTimeout(TimeValue.timeValueSeconds(1))
502+
.build();
501503

502504
SearchRequestBuilder searchRequestBuilder = requestFactory.searchRequestBuilder(client, query, Person.class,
503505
IndexCoordinates.of("persons"));
504506

505507
assertThat(searchRequestBuilder.request().source().timeout()).isEqualTo(TimeValue.timeValueSeconds(1));
506508
}
507509

508-
509510
private String requestToString(ToXContent request) throws IOException {
510511
return XContentHelper.toXContent(request, XContentType.JSON, true).utf8ToString();
511512
}

0 commit comments

Comments
 (0)