ElasticSearch logger, log entire source on error

六眼飞鱼酱① 提交于 2021-02-11 13:53:57

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!