Skip to content

Commit b0ef533

Browse files
authored
Add scroll info to search task description (#54606)
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 ee9442d commit b0ef533

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
@@ -611,8 +611,10 @@ public String getDescription() {
611611
Strings.arrayToDelimitedString(indices, ",", sb);
612612
sb.append("], ");
613613
sb.append("search_type[").append(searchType).append("], ");
614+
if (scroll != null) {
615+
sb.append("scroll[").append(scroll.keepAlive()).append("], ");
616+
}
614617
if (source != null) {
615-
616618
sb.append("source[").append(source.toString(FORMAT_PARAMS)).append("]");
617619
} else {
618620
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
@@ -30,14 +30,17 @@
3030
import org.elasticsearch.search.Scroll;
3131
import org.elasticsearch.search.builder.SearchSourceBuilder;
3232
import org.elasticsearch.search.rescore.QueryRescorerBuilder;
33+
import org.elasticsearch.tasks.TaskId;
3334
import org.elasticsearch.test.ESTestCase;
3435
import org.elasticsearch.test.VersionUtils;
3536

3637
import java.io.IOException;
3738
import java.util.ArrayList;
3839
import java.util.List;
3940

41+
import static java.util.Collections.emptyMap;
4042
import static org.elasticsearch.test.EqualsHashCodeTestUtils.checkEqualsAndHashCode;
43+
import static org.hamcrest.Matchers.equalTo;
4144

4245
public class SearchRequestTests extends AbstractSearchTestCase {
4346

@@ -193,4 +196,17 @@ private SearchRequest mutate(SearchRequest searchRequest) {
193196
randomFrom(mutators).run();
194197
return mutation;
195198
}
199+
200+
public void testDescriptionForDefault() {
201+
assertThat(toDescription(new SearchRequest()), equalTo("indices[], search_type[QUERY_THEN_FETCH], source[]"));
202+
}
203+
204+
public void testDescriptionIncludesScroll() {
205+
assertThat(toDescription(new SearchRequest().scroll(TimeValue.timeValueMinutes(5))),
206+
equalTo("indices[], search_type[QUERY_THEN_FETCH], scroll[5m], source[]"));
207+
}
208+
209+
private String toDescription(SearchRequest request) {
210+
return request.createTask(0, "test", SearchAction.NAME, TaskId.EMPTY_TASK_ID, emptyMap()).getDescription();
211+
}
196212
}

0 commit comments

Comments
 (0)