Skip to content

[FEATURE] Throw OpenSearchException on 409 Conflict #749

@rursprung

Description

@rursprung

Is your feature request related to a problem?

note: i'm using the ApacheHttpClient5Transport APIs.

i'm doing a request through OpenSearchClient#create because the API allows me to ensure that a document is only indexed once, as per the javadoc:

/**
* Creates a new document in the index.
* <p>
* Returns a 409 response when a document with a same ID already exists in the
* index.
*
*
*/
public <TDocument> CreateResponse create(CreateRequest<TDocument> request) throws IOException, OpenSearchException {

however, if the document with this ID already exists then the API throws an exception instead of returning a response. and while the ResponseException would offer access to the actual Response:


which would also offer access to the HTTP status via StatusLine:
public StatusLine getStatusLine() {
return new StatusLine(response);
}

the problem is that Response is package-private, so i cannot access any of its methods (even though they're marked as public):

What solution would you like?

there should be a clear, canonical (and documented) way of accessing the HTTP status if such a request fails.

one possibility could be to make Response public (i don't understand why it isn't).

What alternatives have you considered?

parsing the exception as a string to see if it contains "[HTTP/1.1 409 Conflict]" is at best an ugly hack as the string is not a guaranteed API

Do you have any additional context?

i wasn't sure whether to categorise this as a feature request (because it needs a new API to be exposed), a bug report (because i consider it wrong that i can't access this information) or a question (because i might just have missed a way of getting to that information; in that case it'd be good if it could be documented as i didn't find it in this repo!).

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions