{"record":{"id":"26fae6ea00d9eda8","repo":"elastic/elasticsearch","slug":"http-method-not-supported","errorCode":null,"errorMessage":"http method not supported: {}","messagePattern":"http method not supported: (.+?)","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"client/rest/src/main/java/org/elasticsearch/client/RestClient.java","lineNumber":620,"sourceCode":"                return addRequestBody(new HttpDeleteWithEntity(uri), entity, compressionEnabled);\n            case HttpGetWithEntity.METHOD_NAME:\n                return addRequestBody(new HttpGetWithEntity(uri), entity, compressionEnabled);\n            case HttpHead.METHOD_NAME:\n                return addRequestBody(new HttpHead(uri), entity, compressionEnabled);\n            case HttpOptions.METHOD_NAME:\n                return addRequestBody(new HttpOptions(uri), entity, compressionEnabled);\n            case HttpPatch.METHOD_NAME:\n                return addRequestBody(new HttpPatch(uri), entity, compressionEnabled);\n            case HttpPost.METHOD_NAME:\n                HttpPost httpPost = new HttpPost(uri);\n                addRequestBody(httpPost, entity, compressionEnabled);\n                return httpPost;\n            case HttpPut.METHOD_NAME:\n                return addRequestBody(new HttpPut(uri), entity, compressionEnabled);\n            case HttpTrace.METHOD_NAME:\n                return addRequestBody(new HttpTrace(uri), entity, compressionEnabled);\n            default:\n                throw new UnsupportedOperationException(\"http method not supported: \" + method);\n        }\n    }\n\n    private static HttpRequestBase addRequestBody(HttpRequestBase httpRequest, HttpEntity entity, boolean compressionEnabled) {\n        if (entity != null) {\n            if (httpRequest instanceof HttpEntityEnclosingRequestBase) {\n                if (compressionEnabled) {\n                    entity = new ContentCompressingEntity(entity);\n                }\n                ((HttpEntityEnclosingRequestBase) httpRequest).setEntity(entity);\n            } else {\n                throw new UnsupportedOperationException(httpRequest.getMethod() + \" with body is not supported\");\n            }\n        }\n        return httpRequest;\n    }\n\n    static URI buildUri(String pathPrefix, String path, Map<String, String> params) {","sourceCodeStart":602,"sourceCodeEnd":638,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/client/rest/src/main/java/org/elasticsearch/client/RestClient.java#L602-L638","documentation":"Thrown by RestClient.createHttpRequest when the HTTP method string does not match any of GET, DELETE, HEAD, OPTIONS, PATCH, POST, PUT, TRACE. The supported set is fixed by the Apache HttpClient request types the client instantiates; anything else hits the default branch and raises UnsupportedOperationException.","triggerScenarios":"Passing an unsupported method name to new Request(method, ...) or RequestOptions, e.g. \"CONNECT\", \"MERGE\", or a typo like \"GETT\". Case must match constants exactly (HttpGet.METHOD_NAME etc.).","commonSituations":"Typo in the method string; trying to use a custom HTTP verb the client doesn't model; copy-pasting a method from another library that supports CONNECT.","solutions":["Use one of the supported verbs exactly: GET, POST, PUT, DELETE, HEAD, OPTIONS, PATCH, TRACE.","Check the literal passed to new Request(method, endpoint) for typos and casing.","If you need CONNECT or a custom verb, you cannot do it through this client; fork/extend createHttpRequest."],"exampleFix":"// before\nRequest req = new Request(\"GETT\", \"/index/_search\");\n// after\nRequest req = new Request(\"GET\", \"/index/_search\");","handlingStrategy":"validation","validationCode":"private static final Set<String> SUPPORTED = Set.of(\"GET\",\"POST\",\"PUT\",\"DELETE\",\"HEAD\",\"OPTIONS\",\"PATCH\",\"TRACE\");\nif (!SUPPORTED.contains(method)) throw new IllegalArgumentException(\"unsupported HTTP method: \" + method);\nRequest req = new Request(method, endpoint);","typeGuard":null,"tryCatchPattern":"try { new Request(method, endpoint); }\ncatch (UnsupportedOperationException e) {\n    if (e.getMessage().startsWith(\"http method not supported\")) throw new IllegalArgumentException(\"bad method from caller\", e);\n    throw e;\n}","preventionTips":["Centralise HTTP-method construction in a helper that whitelists verbs.","Reject unknown methods at the API boundary of your own code, not at the client."],"tags":["rest-client","http-method","request"],"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-12T06:17:24.410Z"}