class DefaultShardOperationFailedException extends ShardOperationFailedException {

    private static final String INDEX = "index";
    private static final String SHARD_ID = "shard";
    private static final String REASON = "reason";

    private static final ConstructingObjectParser<DefaultShardOperationFailedException, Void> PARSER = new ConstructingObjectParser<>(
        "failures", true, arg -> new DefaultShardOperationFailedException((String) arg[0], (int) arg[1] ,(Throwable) arg[2]));

    static {
        PARSER.declareString(constructorArg(), new ParseField(INDEX));
        PARSER.declareInt(constructorArg(), new ParseField(SHARD_ID));
        PARSER.declareObject(constructorArg(), (p, c) -> ElasticsearchException.fromXContent(p), new ParseField(REASON));
    }

    public DefaultShardOperationFailedException(ElasticsearchException e) {
        super(
            e.getIndex() == null ? null : e.getIndex().getName(),
            e.getShardId() == null ? -1 : e.getShardId().id(),
            Exceptions.stackTrace(e),
            e.status(),
            e
        );
    }

    public DefaultShardOperationFailedException(String index, int shardId, Throwable cause) {
        super(index, shardId, Exceptions.stackTrace(cause), SQLExceptions.status(cause), cause);
    }

    public DefaultShardOperationFailedException(StreamInput in) throws IOException {
        index = in.readOptionalString();
        shardId = in.readVInt();
        cause = in.readException();
        status = RestStatus.readFrom(in);
    }

    @Override
    public void writeTo(StreamOutput out) throws IOException {
        out.writeOptionalString(index);
        out.writeVInt(shardId);
        out.writeException(cause);
        RestStatus.writeTo(out, status);
    }

    @Override
    public String toString() {<FILL_FUNCTION_BODY>}

    @Override
    public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
        builder.startObject();
        innerToXContent(builder, params);
        builder.endObject();
        return builder;
    }

    protected XContentBuilder innerToXContent(XContentBuilder builder, Params params) throws IOException {
        builder.field("shard", shardId());
        builder.field("index", index());
        builder.field("status", status.name());
        if (reason != null) {
            builder.startObject("reason");
            ElasticsearchException.generateThrowableXContent(builder, params, cause);
            builder.endObject();
        }
        return builder;
    }

    public static DefaultShardOperationFailedException fromXContent(XContentParser parser) {
        return PARSER.apply(parser, null);
    }
}

        return "[" + index + "][" + shardId + "] failed, reason [" + reason() + "]";
    
<methods>public final java.lang.Throwable getCause() ,public final java.lang.String index() ,public final java.lang.String reason() ,public final int shardId() ,public final org.elasticsearch.rest.RestStatus status() <variables>protected java.lang.Throwable cause,protected java.lang.String index,protected java.lang.String reason,protected int shardId,protected org.elasticsearch.rest.RestStatus status