{"record":{"id":"2fbc7f2c5c90989a","repo":"apache/seatunnel","slug":"common-sql-operation-failed-2fbc7f","errorCode":"COMMON_SQL_OPERATION_FAILED","errorMessage":"ElasticSearch execute batch statement error","messagePattern":"ElasticSearch execute batch statement error","errorType":"error_code","errorClass":"ElasticsearchConnectorException","httpStatus":null,"severity":"critical","filePath":"seatunnel-connectors-v2/connector-elasticsearch/src/main/java/org/apache/seatunnel/connectors/seatunnel/elasticsearch/sink/ElasticsearchSinkWriter.java","lineNumber":261,"sourceCode":"        try {\n            RetryUtils.retryWithException(\n                    () -> {\n                        if (!requestEsList.isEmpty()) {\n                            String requestBody = String.join(\"\\n\", requestEsList) + \"\\n\";\n                            BulkResponse bulkResponse = esRestClient.bulk(requestBody);\n                            if (bulkResponse.isErrors()) {\n                                throw new ElasticsearchConnectorException(\n                                        ElasticsearchConnectorErrorCode.BULK_RESPONSE_ERROR,\n                                        \"bulk es error: \" + bulkResponse.getResponse());\n                            }\n                            return bulkResponse;\n                        }\n                        return null;\n                    },\n                    retryMaterial);\n            requestEsList.clear();\n        } catch (Exception e) {\n            throw new ElasticsearchConnectorException(\n                    CommonErrorCodeDeprecated.SQL_OPERATION_FAILED,\n                    \"ElasticSearch execute batch statement error\",\n                    e);\n        }\n    }\n\n    @Override\n    public void close() {\n        if (esRestClient == null) {\n            return;\n        }\n        try {\n            bulkEsWithRetry(this.esRestClient, this.requestEsList);\n        } finally {\n            releaseSharedClientResource();\n            closeOwnedClient();\n        }\n    }","sourceCodeStart":243,"sourceCodeEnd":279,"githubUrl":"https://github.com/apache/seatunnel/blob/cf67b549a7a6c35fa0beb12d83c62892427ea919/seatunnel-connectors-v2/connector-elasticsearch/src/main/java/org/apache/seatunnel/connectors/seatunnel/elasticsearch/sink/ElasticsearchSinkWriter.java#L243-L279","documentation":"bulkEsWithRetry wraps the entire retry-and-bulk execution in a try/catch; any Exception (I/O failure, exhausted retries, client errors) is rethrown as ElasticsearchConnectorException with COMMON_SQL_OPERATION_FAILED and message 'ElasticSearch execute batch statement error', preserving the original cause.","triggerScenarios":"esRestClient.bulk throws or retries are exhausted during write, prepareCommit, timerFlush, or close — e.g. connection failures, timeouts, or the BULK_RESPONSE_ERROR from [997] after all retries.","commonSituations":"ES node unreachable/wrong host:port, authentication failures, network partitions, cluster overload, or persistent per-item bulk errors that survive retries.","solutions":["Check the 'Caused by' chain: if it ends in BULK_RESPONSE_ERROR, fix the per-item bulk issues; if network, fix connectivity","Verify ES host/port/credentials in sink options and test with curl","Increase retry policy (attempts/backoff) for transient cluster issues","Check ES cluster health, disk watermarks, and load"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// preflight: verify ES reachability before the job\n// curl -u user:pass http://host:9200/_cluster/health","typeGuard":null,"tryCatchPattern":"try {\n    writer.prepareCommit();\n} catch (ElasticsearchConnectorException e) {\n    Throwable cause = e.getCause();\n    log.error(\"ES batch write failed; root cause: \" + (cause == null ? \"n/a\" : cause.toString()), e);\n    throw e;\n}","preventionTips":["Verify ES host/port/credentials with a health-check before submitting jobs","Tune retry policy (attempts/backoff) for transient failures","Monitor cluster health, load, and disk watermarks","Reduce write parallelism/batch size if the cluster is overloaded"],"tags":["elasticsearch","bulk-write","connection","retry-exhausted"],"backgroundTag":"database-write-failed","analyzedSha":"cf67b549a7a6c35fa0beb12d83c62892427ea919","analyzedAt":"2026-09-10T21:44:55.265Z","contentChangedAt":"2026-09-10T21:44:55.265Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}