# Pass percentile aggregation bucket values as params to a function\_score/script\_score filter

**URL:** <https://discuss.elastic.co/t/pass-percentile-aggregation-bucket-values-as-params-to-a-function-score-script-score-filter/200290>\
**Category:** Elasticsearch\
**Tags:** painless\
**Created:** [September 19, 2019, 6:34pm UTC](https://discuss.elastic.co/t/pass-percentile-aggregation-bucket-values-as-params-to-a-function-score-script-score-filter/200290 "2019-09-19T18:34:19Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Julian\_Gore](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/julian_gore/32/47285_2.png) [@Julian\_Gore](https://discuss.elastic.co/u/Julian_Gore)\
**Post date:** [September 19, 2019, 6:34pm UTC](https://discuss.elastic.co/t/pass-percentile-aggregation-bucket-values-as-params-to-a-function-score-script-score-filter/200290/1 "2019-09-19T18:34:19Z")

</div>

Hey, am looking for a way to pass values from a percentile aggregation to a function\_score filter as a param in the script\_score field, is this possible?

Something like this:

```
aggs: {
		query_percentiles: {
			percentiles: {
				keyed: false,
				script: {
					lang: "painless",
					source:
						"doc['field'].value"
				},
			},
		},
		aggs: {
			filter: {
				function_score: {
					query: {
						match_all: {}
					},
					functions: [
						{
							script_score: {
								script: {
									params: {
										percentiles: bucket_percentiles?
									},
									source: `bucket_percentiles[i].value>doc[field].value`
								}
							}
						}
					],

				}
			}
		}
	}
```

---

<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:** [October 17, 2019, 6:34pm UTC](https://discuss.elastic.co/t/pass-percentile-aggregation-bucket-values-as-params-to-a-function-score-script-score-filter/200290/2 "2019-10-17T18:34:22Z")

</div>

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