# Global Variable for Script Filter

**URL:** https://discuss.elastic.co/t/global-variable-for-script-filter/18334
**Category:** Elasticsearch
**Created:** [June 25, 2014, 2:51pm UTC](https://discuss.elastic.co/t/global-variable-for-script-filter/18334 "2014-06-25T14:51:59Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![bbehling](https://avatars.discourse-cdn.com/v4/letter/b/f1d935/32.png) [@bbehling](https://discuss.elastic.co/u/bbehling)
#### Post date: [June 25, 2014, 2:51pm UTC](https://discuss.elastic.co/t/global-variable-for-script-filter/18334/1 "2014-06-25T14:51:59Z")

</div>

I'm using the following script filter:

```
{
  "query": {
    "filtered": {
      "filter": {
        "and": [
          {
            "or": [
              {
                "term": {
                  "states": "co"
                }
              }
            ]
          },
          {
             
        "script" : {
            "script" : "count++; count <= 3",
            "params" : {
                "count" : 0
            }
        }
          }
        ]
      }
      
    }
  }
}

```

With this query, I'm expecting to get one results back. But since we have 5  
shards set up on our ES server, I actually get back 15 results.

Is there a way with a script filter to make the count variable global, or  
so that the variable is not reset when searching another shard?

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/a9a3d940-da1e-4e6e-ada5-8e9a7ce9fc4e%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/a9a3d940-da1e-4e6e-ada5-8e9a7ce9fc4e%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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: [July 6, 2017, 1:19am UTC](https://discuss.elastic.co/t/global-variable-for-script-filter/18334/2 "2017-07-06T01:19:49Z")

</div>


