# Filter based on String variable using Script Query

**URL:** <https://discuss.elastic.co/t/filter-based-on-string-variable-using-script-query/119776>\
**Category:** Elasticsearch\
**Created:** [February 14, 2018, 11:01am UTC](https://discuss.elastic.co/t/filter-based-on-string-variable-using-script-query/119776 "2018-02-14T11:01:17Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![volle](https://avatars.discourse-cdn.com/v4/letter/v/a88e57/32.png) [@volle](https://discuss.elastic.co/u/volle)\
**Post date:** [February 14, 2018, 11:01am UTC](https://discuss.elastic.co/t/filter-based-on-string-variable-using-script-query/119776/1 "2018-02-14T11:01:17Z")

</div>

I wish to set up a filter in my dashboard using painless script. I wish to do a query for a field ,named 'message', for the text 'foo' , in turn, run a script to get text from another field called activity\_id, assign it to a string variable and then filter based on value in the string variable. I've tried googling this matter and was unable to find a solution. Code is below that might show easier what I'm trying to achieve.

```
  {
  "query":{
    "bool":{
      "must":[ 
        {"match":{"message": "foo"}}
          ],
          "filter": {
              "script": {
                "script": {
                  "source": "String tester = doc['activity_id.keyword'].value"
          }
        }
      },"should": [
        {"match": {
          "activity_id":{
            "query": "tester"
          } 
        }}
      ]
    }
  }
}
```

---

<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 14, 2018, 11:01am UTC](https://discuss.elastic.co/t/filter-based-on-string-variable-using-script-query/119776/2 "2018-03-14T11:01:41Z")

</div>

Closed on March 14, 2018, 11:01am UTC

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