Update by query with params

[ESK 7.6.2]

We're set country name by phone prefix. if for some reason we hanve't the prefix we're putting "Missing Country Name" string.

I built a simple update by query in Kiban dev-tool and it's worked, now I want to upgrade the script by adding variables:

POST mydata/_update_by_query
{
"script" : {
    "params": {
      "phonePrefix" : 31,
      "newCountryName" : "Netherlands"
    },
    "source": "ctx._source.countryName = params.newCountryName"
  },
  "query" : {
    "bool" : { 
      "must" : [
        { 
          "match": {
            "countryName.keyword": "Missing Country Name"
          }
        },
        { 
          "prefix": {
            "internationalPrefix": {
              "value": "params.phonePrefix"
            }
          }
        }
      ]
    }
  }
}

But it's not working with params (not find documents to update)

Can you help me please? Thank you!

Please provide a full reproducible example including index creation, sample document indexing and reindexing request.

My assumption here is, that your query does not return any results because you are searching for params.phonePrefix as field content in internationalPrefix, try using 31 hardcoded in there, the parameters are only valid within your script.

Thank you Alexander.

index is created via code, but both fields are of text type:

 "countryName" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        }

Without params all works fine, like this:

POST cdrdata*/_update_by_query
{
  "script" : {
    "source": "ctx._source.countryName = 'Netherlands'"
  },
  "query" : {
    "bool" : { 
      "must" : [
        { 
          "match": {
            "countryName.keyword": "Missing Country Name"
          }
        },
        { 
          "prefix": {
            "internationalPrefix": {
              "value": 31
            }
          }
        }
      ]
    }
  }
}

But I want to use variables in the source and in the query (a friend from the support should use it and I'll be glad to make it easy as I can to him)

Thank you!