Filters Bucket Aggregation using script fields and custom params

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"
        }
      }
    }

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