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

Ajay Takur
  • 6,079
  • 5
  • 39
  • 55

1 Answers1

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.

Val
  • 207,596
  • 13
  • 358
  • 360
  • { "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" – Ajay Takur Aug 24 '23 at 07:50
  • 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 script – Val Aug 24 '23 at 07:55
  • 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? – Ajay Takur Aug 24 '23 at 07:57
  • How about in prod environments if we are calling to script file using update by query from java program? – Ajay Takur Aug 24 '23 at 08:00
  • 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. – Val Aug 24 '23 at 08:21
  • yes did it thanks val ! – Ajay Takur Aug 29 '23 at 12:25
  • Cool, glad it helped! – Val Aug 29 '23 at 12:36