Add types and stats to search slow log

closes #2455
This commit is contained in:
Shay Banon 2012-12-02 22:01:17 +01:00
parent 6021515567
commit a274d9386f
2 changed files with 23 additions and 2 deletions

View File

@ -1293,10 +1293,13 @@ public class Strings {
* @return the delimited String
*/
public static String collectionToDelimitedString(Iterable coll, String delim, String prefix, String suffix) {
return collectionToDelimitedString(coll, delim, prefix, suffix, new StringBuilder());
}
public static String collectionToDelimitedString(Iterable coll, String delim, String prefix, String suffix, StringBuilder sb) {
if (Iterables.isEmpty(coll)) {
return "";
}
StringBuilder sb = new StringBuilder();
Iterator it = coll.iterator();
while (it.hasNext()) {
sb.append(prefix).append(it.next()).append(suffix);
@ -1339,10 +1342,13 @@ public class Strings {
* @return the delimited String
*/
public static String arrayToDelimitedString(Object[] arr, String delim) {
return arrayToDelimitedString(arr, delim, new StringBuilder());
}
public static String arrayToDelimitedString(Object[] arr, String delim, StringBuilder sb) {
if (isEmpty(arr)) {
return "";
}
StringBuilder sb = new StringBuilder();
for (int i = 0; i < arr.length; i++) {
if (i > 0) {
sb.append(delim);

View File

@ -20,6 +20,7 @@
package org.elasticsearch.index.search.slowlog;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.logging.ESLogger;
import org.elasticsearch.common.logging.Loggers;
@ -188,6 +189,20 @@ public class ShardSlowLogSearchService extends AbstractIndexShardComponent {
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("took[").append(TimeValue.timeValueNanos(tookInNanos)).append("], took_millis[").append(TimeUnit.NANOSECONDS.toMillis(tookInNanos)).append("], ");
if (context.types() == null) {
sb.append("types[], ");
} else {
sb.append("types[");
Strings.arrayToDelimitedString(context.types(), ",", sb);
sb.append("], ");
}
if (context.groupStats() == null) {
sb.append("stats[], ");
} else {
sb.append("stats[");
Strings.collectionToDelimitedString(context.groupStats(), ",", "", "", sb);
sb.append("], ");
}
sb.append("search_type[").append(context.searchType()).append("], total_shards[").append(context.numberOfShards()).append("], ");
if (context.request().source() != null && context.request().source().length() > 0) {
try {