# Token filter predicate script and query-time 'params'

**URL:** <https://discuss.elastic.co/t/token-filter-predicate-script-and-query-time-params/295752>\
**Category:** Elasticsearch\
**Tags:** painless\
**Created:** [January 29, 2022, 1:56pm UTC](https://discuss.elastic.co/t/token-filter-predicate-script-and-query-time-params/295752 "2022-01-29T13:56:55Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![softwaredoug](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/softwaredoug/32/22681_2.png) [@softwaredoug](https://discuss.elastic.co/u/softwaredoug)\
**Post date:** [January 29, 2022, 1:56pm UTC](https://discuss.elastic.co/t/token-filter-predicate-script-and-query-time-params/295752/1 "2022-01-29T13:56:55Z")

</div>

Hello!

I have been spelunking through Elastic code to try to understand how the following is possible. The [Analysis Predicate Context](https://www.elastic.co/guide/en/elasticsearch/painless/current/painless-analysis-predicate-context.html) says that painless scripts run at analysis can accept query-time params"

> `params` ( `Map` , read-only)
> 
> User-defined parameters passed in as part of the query.

However, I'm unable to figure out if this is actually true or not. Because the "script" body appears as a mapping definition, I would not expect to be able to pass "params" anywhere (there's no specific place in a query to pass in query time params for analysis scripts?)

Indeed in the associated PR, I do not see any reference to "Query Time Params"

> <https://github.com/elastic/elasticsearch/pull/33431/files>
>
> This will allow users to filter out terms using scripted predicates, rather than… having to write Java code and wiring things up via analysis plugins.

I was hoping that this note in the docs pointed at a way to change analyzer settings per-query (aside from changing the `analyzer` itself. But I don't see any such code, and given my knowledge of Lucene, etc, I wouldn't expect to find an ability to change analyzer internal params per query.

Is this correct? I just want to confirm my understanding that the docs may actually be incorrect here?

Happy to send in a PR of course, just want to confirm 🙂

---

<div class="post-metadata">

**Author:** ![Tomo\_M](https://avatars.discourse-cdn.com/v4/letter/t/848f3c/32.png) [@Tomo\_M](https://discuss.elastic.co/u/Tomo_M)\
**Post date:** [January 29, 2022, 3:37pm UTC](https://discuss.elastic.co/t/token-filter-predicate-script-and-query-time-params/295752/2 "2022-01-29T15:37:07Z")

</div>

In general, script has the structure:

```auto
{
  "script":{
    "source": "<some script>",
    "params": {<params map>}
  }
}

```

So I suppose [Predicate script token filter](https://www.elastic.co/guide/en/elasticsearch/reference/master/analysis-predicatefilter-tokenfilter.html) can contain params paramter. Do I undestand your question correctly??

---

<div class="post-metadata">

**Author:** ![softwaredoug](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/softwaredoug/32/22681_2.png) [@softwaredoug](https://discuss.elastic.co/u/softwaredoug)\
**Post date:** [January 31, 2022, 4:41pm UTC](https://discuss.elastic.co/t/token-filter-predicate-script-and-query-time-params/295752/3 "2022-01-31T16:41:21Z")

</div>

Yes!

My question is more a clarification

- The script is defined at **index time**
- The "params" say they are passed at **query time**

But I think params are really defined in the context the script is used, and in the case of analyzers, you can't really pass params along with the query that uses the analyzer itself...

---

<div class="post-metadata">

**Author:** ![Tomo\_M](https://avatars.discourse-cdn.com/v4/letter/t/848f3c/32.png) [@Tomo\_M](https://discuss.elastic.co/u/Tomo_M)\
**Post date:** [February 1, 2022, 12:07pm UTC](https://discuss.elastic.co/t/token-filter-predicate-script-and-query-time-params/295752/4 "2022-02-01T12:07:05Z")

</div>

I found you are right. I tried some places (index settings, field settings and in query), and I couldn't pass params to script everywhere..

---

<div class="post-metadata">

**Author:** ![stu](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stu/32/75063_2.png) [@stu](https://discuss.elastic.co/u/stu)\
**Post date:** [February 1, 2022, 6:50pm UTC](https://discuss.elastic.co/t/token-filter-predicate-script-and-query-time-params/295752/5 "2022-02-01T18:50:32Z")

</div>

@softwaredoug The documentation is wrong, this context does not [take params](https://github.com/elastic/elasticsearch/blob/master/modules/analysis-common/src/main/java/org/elasticsearch/analysis/common/AnalysisPredicateScript.java#L103). We'll update the documentation.

What are you trying to achieve with params here?

---

<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 1, 2022, 6:51pm UTC](https://discuss.elastic.co/t/token-filter-predicate-script-and-query-time-params/295752/6 "2022-03-01T18:51:25Z")

</div>

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