Get Document APIs throw incorrect method error

Versions (relevant - OpenSearch/Dashboard/Server OS/Browser):


Describe the issue:

OpenSearchClient#get(GetRequest) throws:

Request failed: [string_error] Incorrect HTTP method for uri [/my_index/_doc/] and method [GET], allowed: [POST]

on usage:

val request = GetRequest.Builder()

val response = client.get(request,

making http request works just fine:

GET localhost:9200/my_index/_doc/1001
Content-Type: application/json

I think the error makes sense because the uri supposed to be /my_index/_doc/1001 instead of /my_index/_doc/? as per get document API.

to not mistaken with index document API which has an option for POST <index>/_doc.

Relevant Logs or Screenshots:

In RestClientTransport:

    public <RequestT, ResponseT, ErrorT> ResponseT performRequest(RequestT request, Endpoint<RequestT, ResponseT, ErrorT> endpoint, @Nullable TransportOptions options) throws IOException {
        Request clientReq = this.prepareLowLevelRequest(request, endpoint, options);
        Response clientResp = this.restClient.performRequest(clientReq);
        return this.getHighLevelResponse(clientResp, endpoint);

Hey @danngyn

You using cURL or Dev tools to make those request?

The http request cURL-like syntax is IntelliJ built-in HTTP Client.
For that, I just follow the docs and type in <host>/<index>/_doc/<doc-id>, which works as expected.

As for the java client (I use kotlin), the output request seems to miss <doc-id> part?


understood, as for kotlin I haven’t used that for a java client so I’m unsure.

@danngyn I believe in your use case, the _id of the document is not passed into GetRequest (it is not set).

I did have it, also posted in the snippet above:

val request = GetRequest.Builder()

Oh sorry, I was looking into the screenshots of Idea (which didn’t much this snippet). I am quite confused by this call val response = client.get(request), I suppose the client is OpenSearchClient instance?

yes it’s an instance of org.opensearch.client.opensearch.OpenSearchClient

sorry i missed the 2nd arg, edited, and should be val response = client.get(request,

Ah that explains it, thank you. I doubt this is Kotlin specific, but I cannot reproduce the issue with the Java snippet, may I ask you please to try out with the latest OpenSearch Java Client 2.10.2 ?