{"record":{"id":"7f2efdb46f44ce3a","repo":"apache/beam","slug":"errormessages-tostring","errorCode":null,"errorMessage":"<errorMessages.toString()>","messagePattern":"<errorMessages\\.toString\\(\\)>","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"sdks/java/io/elasticsearch/src/main/java/org/apache/beam/sdk/io/elasticsearch/ElasticsearchIO.java","lineNumber":310,"sourceCode":"            || (!allowedErrorTypes.contains(type) && !allowedErrorTypes.contains(cbType))) {\n          // 'error' and 'causedBy` fields are not null, and the error is not being ignored.\n          result = result.withHasError(true);\n          numErrors++;\n\n          errorMessages.append(String.format(\"%nDocument id %s: %s (%s)\", docId, reason, type));\n\n          if (!causedBy.isMissingNode()) {\n            errorMessages.append(String.format(\"%nCaused by: %s (%s)\", cbReason, cbType));\n          }\n        }\n      }\n      responses.add(result);\n    }\n\n    if (numErrors > 0) {\n      LOG.error(\"{}\", errorMessages.toString());\n      if (throwWriteErrors) {\n        throw new IOException(errorMessages.toString());\n      }\n    }\n\n    return responses;\n  }\n\n  /** A POJO describing a connection configuration to Elasticsearch. */\n  @AutoValue\n  public abstract static class ConnectionConfiguration implements Serializable {\n\n    public abstract List<String> getAddresses();\n\n    public abstract @Nullable String getUsername();\n\n    public abstract @Nullable String getPassword();\n\n    public abstract @Nullable String getApiKey();\n","sourceCodeStart":292,"sourceCodeEnd":328,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/io/elasticsearch/src/main/java/org/apache/beam/sdk/io/elasticsearch/ElasticsearchIO.java#L292-L328","documentation":"WriteToElasticsearch batches bulk API requests and collects per-item error messages from Elasticsearch responses. If any bulk item reports an error and throwWriteErrors is enabled, the whole batch fails with an IOException containing all accumulated error messages. This surfaces partial bulk-write failures (mapping conflicts, invalid docs, cluster issues) as a single pipeline failure.","triggerScenarios":"Calling Beam's ElasticsearchIO.write() with .setThrowWriteErrors(true) while some documents in a bulk request fail (e.g. 400 mapping errors, document_parse_exception) — the bulk endpoint returns per-item errors even though the overall HTTP status is 200.","commonSituations":"Documents whose fields don't match the index mapping; index templates rejecting dynamic fields; ES nodes returning partial failures under load; type mismatch between doc and existing mapping after version upgrades.","solutions":["Inspect the aggregated errorMessages in the exception to find the failing documents and their ES error reasons","Fix the offending documents/field types or update the index mapping","If partial success is acceptable, call .setThrowWriteErrors(false) on Write.fromConnectionConfiguration so errors are only logged, not thrown","Check ES cluster health and logs for systemic issues causing item failures"],"exampleFix":"// before\nWrite write = ElasticsearchIO.Write.with(name, connection)\n    .setThrowWriteErrors(true);\n// after (log errors instead of failing the pipeline)\nWrite write = ElasticsearchIO.Write.with(name, connection)\n    .setThrowWriteErrors(false);","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// Cannot catch inside DoFn; decide policy at construction time\ntry {\n  pipeline.apply(ElasticsearchIO.write().setThrowWriteErrors(false));\n} catch (IOException e) {\n  LOG.error(\"Bulk item errors: {}\", e.getMessage());\n}","preventionTips":["Validate document fields against the index mapping before writing","Use explicit mappings and disable dynamic field rejection in dev","Keep throwWriteErrors=false in non-critical paths, true for exactly-once needs"],"tags":["java","elasticsearch","beam","bulk-write"],"backgroundTag":"database-write-failed","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T21:17:11.552Z"}