unable to find script [testfile] in cluster state in elastic search 8.9 v
Asked Answered
D

1

0

I have created a file ie., testfile.painless

ctx._source.b_id=params.b_id;

and just placed the testfile.painless file in the config/scripts folder on cluster node and then tried with _update_by_query

{
    "script": {
        "id":  "testfile",
              "params": {
            "b_id": "1W"
        }

    },
    "query": {
        "bool": {
            "must": [
                {
                    "match": {
                        "a_core": "71"
                    }
                },
                {
                    "match": {
                        "cid": "3IM"
                    }
                }
            ]
        }
    }
}

When I ran the update query then I received with unable to find script [testfile] in cluster state

Deese answered 23/8, 2023 at 18:59 Comment(0)
C
1

Scripts cannot be stored in files anymore, you need to store them in the cluster state like this:

PUT _scripts/testfile
{
   "script": {
      "source": "....source code of your script..."
   }
}

And then you can run your update query like you do now.

Cabin answered 23/8, 2023 at 19:28 Comment(6)
{ "error": {"root_cause": [{"type": "script_exception","reason": "compile error","script_stack": ["params['b_id']"," ^---- HERE"],"script": "params['branch_id']",lang": "painless", "type": "script_exception","reason": "compile error","script_stack": ["params['b_id']"," ^---- HERE"Deese
Ok, that means it's working now and that your script has issues, but that would be a different question in which you can show the content of your scriptCabin
It worked. Thanks. But do I need to manually execute the script file at the cluster level every time any change in the script file?Deese
How about in prod environments if we are calling to script file using update by query from java program?Deese
Glad it worked out! Every time you change your script you need to store it again using the command I gave you, i.e. PUT _scripts/testfile. When done, the script is compiled and available in the cluster state.Cabin
yes did it thanks val !Deese

© 2022 - 2024 — McMap. All rights reserved.