How to reference Elasticsearch variable remotely

I am trying to include a reference to a variable that I have defined on the Elasticsearch side within a query. Running this query in the Dev Tools within Kibana works correctly. However, when I try to execute it through a curl request or the Python Elasticsearch client, I encounter errors. In other words, the same query, when invoked in Dev Tools and transmitted over the internet, works differently.

My method of querying and referencing the variable:

curl -XPOST "http://localhost:9200/index_name/_search" -H "kbn-xsrf: reporting" -H "Content-Type: application/json" -d'
{
   "query":{
      "function_score":{
         "query":{
            "bool":{
               "should":[
                  {
                     "multi_match":{
                        "query":"some keywords"
                     }
                  }
               ]
            }
         },
         "functions":[
            {
               "script_score":{
                  "script":{
                     "lang":"painless",
                     "source":"def somevar = doc['\\''fieldname.keyword'\\''].value; def painlessVariable = params.painlessVariable; painlessVariable.containsKey(somevar) ? Math.log(painlessVariable[somevar]) : 0.0",
                     "params":{
                        "painlessVariable":"${elasticVariable}"
                     }
                  }
               }
            }
         ]
      }
   }
}

The variable is declared in Kibana dev tools.
I'm using Elasticsearch v8.8.2.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.