Add types field to slow logs in 7.x (#44592)

By mistake in 7.x types field was removed from slow logs. Types are
still present in that version, so this have to be present as a JSON
field
relates #41354
backport that was causing this #44178
This commit is contained in:
Przemyslaw Gomulka 2019-07-19 08:31:00 +02:00 committed by GitHub
parent 60785a9fa8
commit 597d2dfaf5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 0 deletions

View File

@ -34,6 +34,7 @@ import org.elasticsearch.search.internal.SearchContext;
import org.elasticsearch.tasks.Task;
import java.nio.charset.Charset;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
@ -170,6 +171,8 @@ public final class SearchSlowLog implements SearchOperationListener {
} else {
messageFields.put("total_hits", "-1");
}
String[] types = context.getQueryShardContext().getTypes();
messageFields.put("types", asJsonArray(types != null ? Arrays.stream(types) : Stream.empty()));
messageFields.put("stats", asJsonArray(context.groupStats() != null ? context.groupStats().stream() : Stream.empty()));
messageFields.put("search_type", context.searchType());
messageFields.put("total_shards", context.numberOfShards());

View File

@ -170,6 +170,7 @@ public class SearchSlowLogTests extends ESSingleNodeTestCase {
assertThat(p.getValueFor("took"), equalTo("10nanos"));
assertThat(p.getValueFor("took_millis"), equalTo("0"));
assertThat(p.getValueFor("total_hits"), equalTo("-1"));
assertThat(p.getValueFor("types"), equalTo("[]"));
assertThat(p.getValueFor("stats"), equalTo("[]"));
assertThat(p.getValueFor("search_type"), Matchers.nullValue());
assertThat(p.getValueFor("total_shards"), equalTo("1"));