# Filters Bucket Aggregation using script fields and custom params

**URL:** <https://discuss.elastic.co/t/filters-bucket-aggregation-using-script-fields-and-custom-params/109975>\
**Category:** Elasticsearch\
**Created:** [December 1, 2017, 6:57pm UTC](https://discuss.elastic.co/t/filters-bucket-aggregation-using-script-fields-and-custom-params/109975 "2017-12-01T18:57:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![gabe\_frz](https://avatars.discourse-cdn.com/v4/letter/g/ba9def/32.png) [@gabe\_frz](https://discuss.elastic.co/u/gabe_frz)\
**Post date:** [December 1, 2017, 6:57pm UTC](https://discuss.elastic.co/t/filters-bucket-aggregation-using-script-fields-and-custom-params/109975/1 "2017-12-01T18:57:02Z")

</div>

I wonder if it is possible to pass a list of parameters that will be shared through all filter buckets, and if it's also possible to use the value of script fields generated on the query inside the aggregation filter script;

Simplifying, I need a query that have a filter but have buckets that count the number of matches of a nested complex filter inside this query:

example pseudoquery:

```
GET test/test-map/_search?size=0
{
      "aggs": {
        "my_filter": {
          "filters": {
            "filters": {
              "isPromotional": {
                "script": {
                  "script": {
                    "inline": """
                    if(params['user_param'] != "ble" && doc['generated_script_field'].value < 2) {
                      return true;
                    }
                    return false;
                    """
                  }
                }
              },
              "isSpecial": {
                "script": {
                  "script": {
                    "inline": """
                    if(params['user_param'] != "bla" && doc['distance'].value == 15.3) {
                      return true;
                    }
                    return false;
                    """
                  }
                }
              }
            }
          },
           "params":
             "user_param": "user-string"
        }
      }
    }
```

---

<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:** [December 29, 2017, 6:57pm UTC](https://discuss.elastic.co/t/filters-bucket-aggregation-using-script-fields-and-custom-params/109975/2 "2017-12-29T18:57:21Z")

</div>

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