opensearch-project / opensearch-project/opensearch-java
[FEATURE] Throw OpenSearchException on 409 Conflict
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 165
- Forks
- 250
- Avg merge
- 1d 18h
- Merged PRs (30d)
- 26
Description
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:
https://github.com/opensearch-project/opensearch-java/blob/c0f51d038c5d0d9b2b13235ee18c1bc555039595/java-client/src/main/java/org/opensearch/client/opensearch/OpenSearchClient.java#L329-L338
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:
https://github.com/opensearch-project/opensearch-java/blob/c0f51d038c5d0d9b2b13235ee18c1bc555039595/java-client/src/main/java/org/opensearch/client/transport/httpclient5/ResponseException.java#L92-L94
which would also offer access to the HTTP status via StatusLine:
https://github.com/opensearch-project/opensearch-java/blob/c0f51d038c5d0d9b2b13235ee18c1bc555039595/java-client/src/main/java/org/opensearch/client/transport/httpclient5/Response.java#L84-L86
the problem is that Response is package-private, so i cannot access any of its methods (even though they're marked as public):
https://github.com/opensearch-project/opensearch-java/blob/c0f51d038c5d0d9b2b13235ee18c1bc555039595/java-client/src/main/java/org/opensearch/client/transport/httpclient5/Response.java#L52
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!).
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with OpenSearchClient#create and the ApacheHttpClient5Transport classes ResponseException and package-private Response referenced in the issue. Review how failed 409 responses are exposed and determine a documented public access path for the HTTP status. Done means callers can identify a 409 Conflict through the supported API without parsing exception text.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100