问题
I'm trying to get extra information from ElasticSearch's logger on MapperParsingException.
The error message looks like
[logs-X][1] failed to execute bulk item (index) index {[logs-X][logs][x], source[n/a, actual length: [2.9kb], max length: 2kb]}
It shows source[n/a..
Is there a way to print the actual source?
回答1:
It's not possible, at least by configuration
There is a constant value set: https://github.com/elastic/elasticsearch/blob/master/server/src/main/java/org/elasticsearch/action/index/IndexRequest.java#L87
static final int MAX_SOURCE_LENGTH_IN_TOSTRING = 2048;
And it's checked https://github.com/elastic/elasticsearch/blob/master/server/src/main/java/org/elasticsearch/action/index/IndexRequest.java#L673
@Override
public String toString() {
String sSource = "_na_";
try {
if (source.length() > MAX_SOURCE_LENGTH_IN_TOSTRING) {
sSource = "n/a, actual length: [" + new ByteSizeValue(source.length()).toString() + "], max length: " +
new ByteSizeValue(MAX_SOURCE_LENGTH_IN_TOSTRING).toString();
} else {
sSource = XContentHelper.convertToJson(source, false);
}
} catch (Exception e) {
// ignore
}
return "index {[" + index + "][" + id + "], source[" + sSource + "]}";
}
来源:https://stackoverflow.com/questions/62990541/elasticsearch-logger-log-entire-source-on-error