Search code examples
elasticsearchelastic-stackelasticsearch-aggregationelasticsearch-dsl

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


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


Solution

  • 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.