diff --git a/core/src/main/java/org/elasticsearch/index/IndexingSlowLog.java b/core/src/main/java/org/elasticsearch/index/IndexingSlowLog.java index b1d8ac188626f..94c3892ef361e 100644 --- a/core/src/main/java/org/elasticsearch/index/IndexingSlowLog.java +++ b/core/src/main/java/org/elasticsearch/index/IndexingSlowLog.java @@ -181,9 +181,9 @@ public String toString() { sb.append("type[").append(doc.type()).append("], "); sb.append("id[").append(doc.id()).append("], "); if (doc.routing() == null) { - sb.append("routing[] "); + sb.append("routing[]"); } else { - sb.append("routing[").append(doc.routing()).append("] "); + sb.append("routing[").append(doc.routing()).append("]"); } if (maxSourceCharsToLog == 0 || doc.source() == null || doc.source().length() == 0) { @@ -193,7 +193,7 @@ public String toString() { String source = XContentHelper.convertToJson(doc.source(), reformat, doc.getXContentType()); sb.append(", source[").append(Strings.cleanTruncate(source, maxSourceCharsToLog)).append("]"); } catch (IOException e) { - sb.append(", source[_failed_to_convert_]"); + sb.append(", source[_failed_to_convert_[").append(e.getMessage()).append("]]"); } return sb.toString(); } diff --git a/core/src/test/java/org/elasticsearch/index/IndexingSlowLogTests.java b/core/src/test/java/org/elasticsearch/index/IndexingSlowLogTests.java index a3d14fc518499..45b0d0aa2475c 100644 --- a/core/src/test/java/org/elasticsearch/index/IndexingSlowLogTests.java +++ b/core/src/test/java/org/elasticsearch/index/IndexingSlowLogTests.java @@ -22,6 +22,7 @@ import org.apache.lucene.document.NumericDocValuesField; import org.elasticsearch.Version; import org.elasticsearch.cluster.metadata.IndexMetaData; +import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; @@ -62,6 +63,16 @@ public void testSlowLogParsedDocumentPrinterSourceToLog() throws IOException { p = new SlowLogParsedDocumentPrinter(index, pd, 10, true, 3); assertThat(p.toString(), containsString("source[{\"f]")); assertThat(p.toString(), startsWith("[foo/123] took")); + + // Throwing a error if source cannot be converted + source = new BytesArray("invalid"); + pd = new ParsedDocument(new NumericDocValuesField("version", 1), SeqNoFieldMapper.SequenceIDFields.emptySeqID(), "id", + "test", null, null, source, XContentType.JSON, null); + p = new SlowLogParsedDocumentPrinter(index, pd, 10, true, 3); + + assertThat(p.toString(), containsString("_failed_to_convert_[Unrecognized token 'invalid':" + + " was expecting ('true', 'false' or 'null')\n" + + " at [Source: org.elasticsearch.common.bytes.BytesReference$MarkSupportingStreamInputWrapper")); } public void testReformatSetting() {