apache/seatunnel · error · ElasticsearchConnectorException

CLEAR_INDEX_DATA_FAILED

CLEAR_INDEX_DATA_FAILED

Error message

POST {endpoint} response null

What it means

EsRestClient performs a POST request (delete-by-query with match_all to clear an index) via the low-level Elasticsearch RestClient and wraps every failure as ElasticsearchConnectorException with CLEAR_INDEX_DATA_FAILED. This specific variant is thrown when performRequest returns a null Response, which should not normally happen with the official client but is guarded defensively. It signals the clear-index operation could not even be evaluated because no HTTP response object came back.

Source

Thrown at seatunnel-connectors-v2/connector-elasticsearch/src/main/java/org/apache/seatunnel/connectors/seatunnel/elasticsearch/client/EsRestClient.java:671

                                "DELETE %s response status code=%d, body=%s",
                                endpoint, response.getStatusLine().getStatusCode(), entity));
            }
        } catch (IOException ex) {
            throw new ElasticsearchConnectorException(
                    ElasticsearchConnectorErrorCode.DROP_INDEX_FAILED, ex);
        }
    }

    public void clearIndexData(String indexName) {
        String endpoint = String.format("/%s/_delete_by_query", indexName.toLowerCase());
        Request request = new Request("POST", endpoint);
        String jsonString = "{ \"query\": { \"match_all\": {} } }";
        request.setJsonEntity(jsonString);

        try {
            Response response = restClient.performRequest(request);
            if (response == null) {
                throw new ElasticsearchConnectorException(
                        ElasticsearchConnectorErrorCode.CLEAR_INDEX_DATA_FAILED,
                        "POST " + endpoint + " response null");
            }
            String entity = EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8);
            if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
                throw new ElasticsearchConnectorException(
                        ElasticsearchConnectorErrorCode.CLEAR_INDEX_DATA_FAILED,
                        String.format(
                                "POST %s response status code=%d, body=%s",
                                endpoint, response.getStatusLine().getStatusCode(), entity));
            }
        } catch (IOException ex) {
            throw new ElasticsearchConnectorException(
                    ElasticsearchConnectorErrorCode.CLEAR_INDEX_DATA_FAILED, ex);
        }
    }

    /**

View on GitHub (pinned to cf67b549a7)

Solutions

  1. Check network/proxy path between SeaTunnel and Elasticsearch; ensure the ES node actually receives the POST and answers
  2. If a custom RestClient wrapper/mock is in play, make performRequest throw on failure instead of returning null
  3. Retry the clear-index operation; transient gateway drops often succeed on retry
  4. If the goal is clearing data, alternatively delete and recreate the index via the ES REST API directly to confirm cluster health

Example fix

// before
Response response = restClient.performRequest(request);
// after
Response response = restClient.performRequest(request);
if (response == null) {
    throw new ElasticsearchConnectorException(
        ElasticsearchConnectorErrorCode.CLEAR_INDEX_DATA_FAILED,
        "POST " + endpoint + " response null");
}
Defensive patterns

Strategy: try-catch

Validate before calling

// pre-check ES reachability
curl -s -o /dev/null -w '%{http_code}' http://es:9200/<index>/_count
// or in Java: perform a cheap HEAD /<index> request before clear-index

Type guard

// Java: narrow the client result before use
if (response == null || response.getStatusLine() == null) {
    throw new IOException("ES returned no response for " + endpoint);
}

Try / catch

try {
    esRestClient.clearIndexData(index);
} catch (ElasticsearchConnectorException e) {
    if (e.getMessage().contains("response null")) {
        // log and retry with backoff; check network/proxy
    } else { throw e; }
}

Prevention

When it happens

Trigger: Calling EsRestClient clear-index/delete-by-query path (POST /{index}/_delete_by_query with {"query":{"match_all":{}}}) when org.elasticsearch.client.Response.restClient.performRequest(request) returns null.

Common situations: Custom or mocked RestClient implementations returning null; exotic proxies or network layers that abort the call without raising IOException; running against an incompatible/gateway front-end in front of Elasticsearch that swallows the request.

Understand the failure class

Background: 'Something went wrong' / 'Request failed (500)' / 'HTTP error! status: 404' — what failed HTTP requests actually mean and how to find the real cause — this error's family across 28 libraries.

Related errors


AI-assisted analysis of apache/seatunnel@cf67b549a7 (2026-09-10). Data as JSON: /api/errors/1eb079f09ed974ff. Report an issue: GitHub.