elastic/elasticsearch · error · UnsupportedOperationException
http method not supported: {}
Error message
http method not supported: {} What it means
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.
Source
Thrown at client/rest/src/main/java/org/elasticsearch/client/RestClient.java:620
return addRequestBody(new HttpDeleteWithEntity(uri), entity, compressionEnabled);
case HttpGetWithEntity.METHOD_NAME:
return addRequestBody(new HttpGetWithEntity(uri), entity, compressionEnabled);
case HttpHead.METHOD_NAME:
return addRequestBody(new HttpHead(uri), entity, compressionEnabled);
case HttpOptions.METHOD_NAME:
return addRequestBody(new HttpOptions(uri), entity, compressionEnabled);
case HttpPatch.METHOD_NAME:
return addRequestBody(new HttpPatch(uri), entity, compressionEnabled);
case HttpPost.METHOD_NAME:
HttpPost httpPost = new HttpPost(uri);
addRequestBody(httpPost, entity, compressionEnabled);
return httpPost;
case HttpPut.METHOD_NAME:
return addRequestBody(new HttpPut(uri), entity, compressionEnabled);
case HttpTrace.METHOD_NAME:
return addRequestBody(new HttpTrace(uri), entity, compressionEnabled);
default:
throw new UnsupportedOperationException("http method not supported: " + method);
}
}
private static HttpRequestBase addRequestBody(HttpRequestBase httpRequest, HttpEntity entity, boolean compressionEnabled) {
if (entity != null) {
if (httpRequest instanceof HttpEntityEnclosingRequestBase) {
if (compressionEnabled) {
entity = new ContentCompressingEntity(entity);
}
((HttpEntityEnclosingRequestBase) httpRequest).setEntity(entity);
} else {
throw new UnsupportedOperationException(httpRequest.getMethod() + " with body is not supported");
}
}
return httpRequest;
}
static URI buildUri(String pathPrefix, String path, Map<String, String> params) {View on GitHub (pinned to db6a809a66)
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.
Example fix
// before
Request req = new Request("GETT", "/index/_search");
// after
Request req = new Request("GET", "/index/_search"); Defensive patterns
Strategy: validation
Validate before calling
private static final Set<String> SUPPORTED = Set.of("GET","POST","PUT","DELETE","HEAD","OPTIONS","PATCH","TRACE");
if (!SUPPORTED.contains(method)) throw new IllegalArgumentException("unsupported HTTP method: " + method);
Request req = new Request(method, endpoint); Try / catch
try { new Request(method, endpoint); }
catch (UnsupportedOperationException e) {
if (e.getMessage().startsWith("http method not supported")) throw new IllegalArgumentException("bad method from caller", e);
throw e;
} Prevention
- 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.
When it happens
Trigger: 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.).
Common situations: 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.
Related errors
- url parameter [{}] has already been set to [{}]
- {} with body is not supported
- can't compare DeadHostStates holding different time supplier
- bufferLimit must be greater than 0
- entity content is too long [{}] for the configured buffer li
AI-assisted analysis of elastic/elasticsearch@db6a809a66 (2026-08-12).
Data as JSON: /api/errors/26fae6ea00d9eda8.
Report an issue: GitHub.