# How to reference Elasticsearch variable remotely

**URL:** <https://discuss.elastic.co/t/how-to-reference-elasticsearch-variable-remotely/352773>\
**Category:** Elasticsearch\
**Tags:** painless\
**Created:** [February 7, 2024, 3:00pm UTC](https://discuss.elastic.co/t/how-to-reference-elasticsearch-variable-remotely/352773 "2024-02-07T15:00:52Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Stan\_Kendzior](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stan_kendzior/32/126277_2.png) [@Stan\_Kendzior](https://discuss.elastic.co/u/Stan_Kendzior)\
**Post date:** [February 7, 2024, 3:00pm UTC](https://discuss.elastic.co/t/how-to-reference-elasticsearch-variable-remotely/352773/1 "2024-02-07T15:00:52Z")

</div>

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:

```auto
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.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [March 6, 2024, 3:01pm UTC](https://discuss.elastic.co/t/how-to-reference-elasticsearch-variable-remotely/352773/2 "2024-03-06T15:01:05Z")

</div>

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