Skip to content

Commit b4feda8

Browse files
authored
Add scroll info to search task description (backport of #54606) (#54612)
Right now you can't tell from the task description whether or not the search is a scroll. This adds that information to the description which is super useful if you are trying to debug a cluster that is running out of scroll contexts.
1 parent 18b6022 commit b4feda8

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

server/src/main/java/org/elasticsearch/action/search/SearchRequest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -651,8 +651,10 @@ public String getDescription() {
651651
Strings.arrayToDelimitedString(types, ",", sb);
652652
sb.append("], ");
653653
sb.append("search_type[").append(searchType).append("], ");
654+
if (scroll != null) {
655+
sb.append("scroll[").append(scroll.keepAlive()).append("], ");
656+
}
654657
if (source != null) {
655-
656658
sb.append("source[").append(source.toString(FORMAT_PARAMS)).append("]");
657659
} else {
658660
sb.append("source[]");

server/src/test/java/org/elasticsearch/action/search/SearchRequestTests.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.elasticsearch.search.Scroll;
3232
import org.elasticsearch.search.builder.SearchSourceBuilder;
3333
import org.elasticsearch.search.rescore.QueryRescorerBuilder;
34+
import org.elasticsearch.tasks.TaskId;
3435
import org.elasticsearch.test.ESTestCase;
3536
import org.elasticsearch.test.VersionUtils;
3637

@@ -39,8 +40,10 @@
3940
import java.util.Base64;
4041
import java.util.List;
4142

43+
import static java.util.Collections.emptyMap;
4244
import static org.elasticsearch.test.EqualsHashCodeTestUtils.checkEqualsAndHashCode;
4345
import static org.hamcrest.Matchers.allOf;
46+
import static org.hamcrest.Matchers.equalTo;
4447
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
4548
import static org.hamcrest.Matchers.lessThanOrEqualTo;
4649

@@ -235,4 +238,17 @@ private SearchRequest mutate(SearchRequest searchRequest) {
235238
randomFrom(mutators).run();
236239
return mutation;
237240
}
241+
242+
public void testDescriptionForDefault() {
243+
assertThat(toDescription(new SearchRequest()), equalTo("indices[], types[], search_type[QUERY_THEN_FETCH], source[]"));
244+
}
245+
246+
public void testDescriptionIncludesScroll() {
247+
assertThat(toDescription(new SearchRequest().scroll(TimeValue.timeValueMinutes(5))),
248+
equalTo("indices[], types[], search_type[QUERY_THEN_FETCH], scroll[5m], source[]"));
249+
}
250+
251+
private String toDescription(SearchRequest request) {
252+
return request.createTask(0, "test", SearchAction.NAME, TaskId.EMPTY_TASK_ID, emptyMap()).getDescription();
253+
}
238254
}

0 commit comments

Comments
 (0)