Skip to content

Random errors when bulk-updating document objects via painless script #56414

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
consulthys opened this issue May 8, 2020 · 10 comments · Fixed by #56421
Closed

Random errors when bulk-updating document objects via painless script #56414

consulthys opened this issue May 8, 2020 · 10 comments · Fixed by #56421
Labels
>bug :Core/Infra/Scripting Scripting abstractions, Painless, and Mustache Team:Core/Infra Meta label for core/infra team triaged Issue has been looked at, and is being left open

Comments

@consulthys
Copy link
Contributor

Elasticsearch version (bin/elasticsearch --version): 7.6.1 on Elastic Cloud

Plugins installed: N/A

JVM version (java -version): Elastic Cloud

OS version (uname -a if on a Unix-like system): Elastic Cloud

Description of the problem including expected versus actual behavior:

I'm getting inconsistent and sporadic errors while updating documents (via script) through the _bulk API. The issue only happens when trying to update objects (i.e. JSON hash) inside the document.

Steps to reproduce:

Here is a way to easily reproduce the problem.

1. First create a sample index+document

POST test/_doc/1
{
  "hash": {}
}

2. Create a script to be used in the bulk update

The script simply replaces the existing hash field with whatever it receives inside the params and adds another field to that hash:

POST _scripts/add-data
{
  "script": {
    "lang": "painless",
    "source": """
    ctx._source.hash = params;
    ctx._source.hash.additionalField = 32;
    """
  }
}
  1. Try to bulk update the document
POST test/_doc/_bulk
{"update":{"_id": "1"}}
{"script": {"id":"add-data", "params":{"addedField": 44}}}

Now the thing is that sometimes the response is OK

{
  "took" : 427,
  "errors" : false,
  "items" : [
    {
      "update" : {
        "_index" : "test",
        "_type" : "_doc",
        "_id" : "1",
        "_version" : 2,
        "result" : "updated",
        "_shards" : {
          "total" : 2,
          "successful" : 2,
          "failed" : 0
        },
        "_seq_no" : 1,
        "_primary_term" : 1,
        "status" : 200
      }
    }
  ]
}

and sometimes it yields this:

{
  "took" : 7,
  "errors" : true,
  "items" : [
    {
      "update" : {
        "_index" : "test",
        "_type" : "_doc",
        "_id" : "1",
        "status" : 400,
        "error" : {
          "type" : "illegal_argument_exception",
          "reason" : "failed to execute script",
          "caused_by" : {
            "type" : "script_exception",
            "reason" : "runtime error",
            "script_stack" : [
              "java.base/java.util.Collections$UnmodifiableMap.put(Collections.java:1457)",
              "ctx._source.hash.additionalField = 32;\n    ",
              "                ^---- HERE"
            ],
            "script" : "add-data",
            "lang" : "painless",
            "caused_by" : {
              "type" : "unsupported_operation_exception",
              "reason" : null
            }
          }
        }
      }
    }
  ]
}

Now I know that params is not modifiable and I'm trying to add a field to it. The error is pretty clear. But I would expect that it always fails, not randomly.

Also worth noting that it makes no difference whether the index has one primary shard or more.

@consulthys consulthys added >bug needs:triage Requires assignment of a team area label labels May 8, 2020
dimitris-athanasiou added a commit to dimitris-athanasiou/elasticsearch that referenced this issue May 8, 2020
Force stopping a DF analytics job whose config exists and that
is stopped should succeed. This was broken by elastic#56360.

Closes elastic#56414
dimitris-athanasiou added a commit that referenced this issue May 8, 2020
Force stopping a DF analytics job whose config exists and that
is stopped should succeed. This was broken by #56360.

Closes #56414
dimitris-athanasiou added a commit that referenced this issue May 8, 2020
…#56424)

Force stopping a DF analytics job whose config exists and that
is stopped should succeed. This was broken by #56360.

Closes #56414

Backport of #56421
@consulthys
Copy link
Contributor Author

@dimitris-athanasiou I'm not sure how this fixes the issue I've reported above... Are you sure about the issue number ? Wasn't it #56419 ?

@hendrikmuhs
Copy link

@consulthys I think you are right, this bug has been accidentally closed via a commit message

@hendrikmuhs hendrikmuhs reopened this May 11, 2020
@hendrikmuhs hendrikmuhs added the :Core/Infra/Scripting Scripting abstractions, Painless, and Mustache label May 11, 2020
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-core-infra (:Core/Infra/Scripting)

@elasticmachine elasticmachine added the Team:Core/Infra Meta label for core/infra team label May 11, 2020
@hendrikmuhs hendrikmuhs removed the needs:triage Requires assignment of a team area label label May 11, 2020
@rjernst rjernst added the needs:triage Requires assignment of a team area label label Dec 3, 2020
@stu-elastic stu-elastic removed the needs:triage Requires assignment of a team area label label Dec 9, 2020
@stu-elastic
Copy link
Contributor

This should always fail, we'll try to reproduce.

@consulthys
Copy link
Contributor Author

@stu-elastic Note that I can still reproduce this in 8.13.3

@rjernst
Copy link
Member

rjernst commented Apr 4, 2025

params is unfortunately not read-only. In some cases it can become read-only (eg passing script object over the wire), but making it read-only across all script contexts is a technically breaking change.

@rjernst rjernst added the triaged Issue has been looked at, and is being left open label Apr 4, 2025
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-core-infra (Team:Core/Infra)

@consulthys
Copy link
Contributor Author

I tested again on 8.17.3 and it now fails consistently.

@rjernst
Copy link
Member

rjernst commented Apr 9, 2025

@consulthys would you consider this fixed then? My reading of the original issue is that the bug was the inconsistency, not that there was an error.

@consulthys
Copy link
Contributor Author

@rjernst yes, that's correct, I originally didn't mind the error, just the inconsistency of it being sometimes reported sometimes not. Feel free to close it.

@rjernst rjernst closed this as completed Apr 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>bug :Core/Infra/Scripting Scripting abstractions, Painless, and Mustache Team:Core/Infra Meta label for core/infra team triaged Issue has been looked at, and is being left open
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants