Skip to content

Expose BulkResponseItem.status in BulkFailureException #2619

Closed
@ilya-ulyanov

Description

@ilya-ulyanov

Hi,

I would like to propose a usability change in BulkFailureException class.

The class provides information on failed documents in form of Map {document._id->BulkResponseItem.reason}:

public class BulkFailureException extends DataRetrievalFailureException {
	private final Map<String, String> failedDocuments;

	public BulkFailureException(String msg, Map<String, String> failedDocuments) {
		super(msg);
		this.failedDocuments = failedDocuments;
	}

	public Map<String, String> getFailedDocuments() {
		return failedDocuments;
	}
}

The problem is that the reason is a string and it is problematic to reason about it when your client code needs to handle those failures in a specific way.

For instance in my project I need to have special handling of conflicts (when an attempt was done to save a document with the same or lower version, HTTP status 409) and currently I have to rely on string message from native elasticsearch library (which could change in the future btw)

It would be great to have the integer status of a particular failure.

Not to introduce a breaking change, I would imagine a new Map to be added as:

public class BulkFailureException extends DataRetrievalFailureException {
	private final Map<String, String> failedDocuments;
        private final Map<String, Integer> failedDocumentStatuses;

	public BulkFailureException(String msg, Map<String, String> failedDocuments, Map<String, Integer> failedDocumentStatuses) {
		super(msg);
		this.failedDocuments = failedDocuments;
                this.failedDocumentStatuses = failedDocumentStatuses;
	}

	public Map<String, String> getFailedDocuments() {
		return failedDocuments;
	}

       public Map<String, Integer> getFailedDocumentStatuses() {
		return failedDocumentStatuses;
	}
}

I could submit a PR if the above makes sense.

Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions