{"record":{"id":"baa90aa73d0b0d06","repo":"apache/beam","slug":"painless-scripts-are-not-supported-on-elasticsearch-clusters","errorCode":null,"errorMessage":"Painless scripts are not supported on Elasticsearch clusters before version 5.0","messagePattern":"Painless scripts are not supported on Elasticsearch clusters before version 5\\.0","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/java/io/elasticsearch/src/main/java/org/apache/beam/sdk/io/elasticsearch/ElasticsearchIO.java","lineNumber":1740,"sourceCode":"     *\n     * <p>When the documents contain\n     *\n     * @param appendOnly set to true to allow only document appending\n     * @return the {@link DocToBulk} with the-append only control set\n     */\n    public DocToBulk withAppendOnly(boolean appendOnly) {\n      return builder().setAppendOnly(appendOnly).build();\n    }\n\n    /**\n     * Whether to use scripted updates and what script to use.\n     *\n     * @param source set to the value of the script source, painless lang\n     * @return the {@link DocToBulk} with the scripted updates set\n     */\n    public DocToBulk withUpsertScript(String source) {\n      if (getBackendVersion() == null || getBackendVersion() == 2) {\n        LOG.warn(\"Painless scripts are not supported on Elasticsearch clusters before version 5.0\");\n      }\n      return builder().setUsePartialUpdate(false).setUpsertScript(source).build();\n    }\n\n    /**\n     * Provide a function to extract the doc version from the document. This version number will be\n     * used as the document version in Elasticsearch. Should the function throw an Exception then\n     * the batch will fail and the exception propagated. Incompatible with update operations and\n     * should only be used with withUsePartialUpdate(false)\n     *\n     * @param docVersionFn to extract the document version\n     * @return the {@link DocToBulk} with the function set\n     */\n    public DocToBulk withDocVersionFn(Write.FieldValueExtractFn docVersionFn) {\n      checkArgument(docVersionFn != null, \"docVersionFn must not be null\");\n      return builder().setDocVersionFn(docVersionFn).build();\n    }\n","sourceCodeStart":1722,"sourceCodeEnd":1758,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/io/elasticsearch/src/main/java/org/apache/beam/sdk/io/elasticsearch/ElasticsearchIO.java#L1722-L1758","documentation":"Error raised by ElasticsearchIO's DocToBulk path when scripted upserts are configured (withUpsertScript) but the target Elasticsearch cluster reports a version below 5.0. Painless scripting did not exist before ES 5.x, so the configured upsert script cannot be executed against that cluster and the write is rejected.","triggerScenarios":"Thrown at sdks/java/io/elasticsearch/src/main/java/org/apache/beam/sdk/io/elasticsearch/ElasticsearchIO.java:1740 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Upgrade the Elasticsearch cluster to 5.0 or later to use painless upsert scripts","Drop withUpsertScript and use plain document appends (appendOnly) on pre-5.0 clusters"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}