Skip to content

Commit a274d93

Browse files
committed
Add types and stats to search slow log
closes elastic#2455
1 parent 6021515 commit a274d93

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

src/main/java/org/elasticsearch/common/Strings.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1293,10 +1293,13 @@ public static Set<String> commaDelimitedListToSet(String str) {
12931293
* @return the delimited String
12941294
*/
12951295
public static String collectionToDelimitedString(Iterable coll, String delim, String prefix, String suffix) {
1296+
return collectionToDelimitedString(coll, delim, prefix, suffix, new StringBuilder());
1297+
}
1298+
1299+
public static String collectionToDelimitedString(Iterable coll, String delim, String prefix, String suffix, StringBuilder sb) {
12961300
if (Iterables.isEmpty(coll)) {
12971301
return "";
12981302
}
1299-
StringBuilder sb = new StringBuilder();
13001303
Iterator it = coll.iterator();
13011304
while (it.hasNext()) {
13021305
sb.append(prefix).append(it.next()).append(suffix);
@@ -1339,10 +1342,13 @@ public static String collectionToCommaDelimitedString(Iterable coll) {
13391342
* @return the delimited String
13401343
*/
13411344
public static String arrayToDelimitedString(Object[] arr, String delim) {
1345+
return arrayToDelimitedString(arr, delim, new StringBuilder());
1346+
}
1347+
1348+
public static String arrayToDelimitedString(Object[] arr, String delim, StringBuilder sb) {
13421349
if (isEmpty(arr)) {
13431350
return "";
13441351
}
1345-
StringBuilder sb = new StringBuilder();
13461352
for (int i = 0; i < arr.length; i++) {
13471353
if (i > 0) {
13481354
sb.append(delim);

src/main/java/org/elasticsearch/index/search/slowlog/ShardSlowLogSearchService.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
package org.elasticsearch.index.search.slowlog;
2121

2222
import org.elasticsearch.cluster.metadata.IndexMetaData;
23+
import org.elasticsearch.common.Strings;
2324
import org.elasticsearch.common.inject.Inject;
2425
import org.elasticsearch.common.logging.ESLogger;
2526
import org.elasticsearch.common.logging.Loggers;
@@ -188,6 +189,20 @@ public SlowLogSearchContextPrinter(SearchContext context, long tookInNanos, bool
188189
public String toString() {
189190
StringBuilder sb = new StringBuilder();
190191
sb.append("took[").append(TimeValue.timeValueNanos(tookInNanos)).append("], took_millis[").append(TimeUnit.NANOSECONDS.toMillis(tookInNanos)).append("], ");
192+
if (context.types() == null) {
193+
sb.append("types[], ");
194+
} else {
195+
sb.append("types[");
196+
Strings.arrayToDelimitedString(context.types(), ",", sb);
197+
sb.append("], ");
198+
}
199+
if (context.groupStats() == null) {
200+
sb.append("stats[], ");
201+
} else {
202+
sb.append("stats[");
203+
Strings.collectionToDelimitedString(context.groupStats(), ",", "", "", sb);
204+
sb.append("], ");
205+
}
191206
sb.append("search_type[").append(context.searchType()).append("], total_shards[").append(context.numberOfShards()).append("], ");
192207
if (context.request().source() != null && context.request().source().length() > 0) {
193208
try {

0 commit comments

Comments
 (0)