Skip to content

Expose BulkResponseItem.status in BulkFailureException #2050

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ilya-ulyanov opened this issue Jul 9, 2023 · 1 comment
Closed

Expose BulkResponseItem.status in BulkFailureException #2050

ilya-ulyanov opened this issue Jul 9, 2023 · 1 comment

Comments

@ilya-ulyanov
Copy link

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 imaging 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.

@ilya-ulyanov
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant