# How can I pass parameters to token filter script in Elasticsearch?

**URL:** <https://discuss.elastic.co/t/how-can-i-pass-parameters-to-token-filter-script-in-elasticsearch/212255>\
**Category:** Elasticsearch\
**Created:** [December 18, 2019, 3:56am UTC](https://discuss.elastic.co/t/how-can-i-pass-parameters-to-token-filter-script-in-elasticsearch/212255 "2019-12-18T03:56:11Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mnguyen.mti](https://avatars.discourse-cdn.com/v4/letter/m/f08c70/32.png) [@mnguyen.mti](https://discuss.elastic.co/u/mnguyen.mti)\
**Post date:** [December 18, 2019, 3:56am UTC](https://discuss.elastic.co/t/how-can-i-pass-parameters-to-token-filter-script-in-elasticsearch/212255/1 "2019-12-18T03:56:11Z")

</div>

I want to do something like the one below, but this code clearly does not work. Is there any way I can pass a predefined parameter to the "source" section?

> term\_temp = "of kerosene, kerosene fuel"  
> predicate\_token\_filter\_temp = {  
> "type" : "predicate\_token\_filter",  
> "script" : {  
> "source": "String additional\_terms = term\_path ;String curr\_token = toke n.getTerm().toString(); !curr\_token.contains(" ") || additional\_terms.contains(curr\_token);",  
> "params": {"term\_path": term\_temp }  
> }  
> }

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [December 18, 2019, 8:50am UTC](https://discuss.elastic.co/t/how-can-i-pass-parameters-to-token-filter-script-in-elasticsearch/212255/2 "2019-12-18T08:50:51Z")

</div>

can you maybe explain in plain english what output you are expecting of what input, completely independent of any code snippet? This might be easier to understand what you are after.

---

<div class="post-metadata">

**Author:** ![mnguyen.mti](https://avatars.discourse-cdn.com/v4/letter/m/f08c70/32.png) [@mnguyen.mti](https://discuss.elastic.co/u/mnguyen.mti)\
**Post date:** [December 18, 2019, 9:05am UTC](https://discuss.elastic.co/t/how-can-i-pass-parameters-to-token-filter-script-in-elasticsearch/212255/3 "2019-12-18T09:05:02Z")

</div>

I want to be able to pass parameters to "predicate\_token\_filter" token filter. In particularly, pass inside "source" section.  
I'm trying to use String additional\_terms = term\_path but it does not work

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [December 18, 2019, 12:20pm UTC](https://discuss.elastic.co/t/how-can-i-pass-parameters-to-token-filter-script-in-elasticsearch/212255/4 "2019-12-18T12:20:31Z")

</div>

that token filter can only see content from the particular field, not from other fields of the document.

Again a concrete use-case might be easier to understand your problem and possibly find a workaround.

---

<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:** [January 15, 2020, 12:20pm UTC](https://discuss.elastic.co/t/how-can-i-pass-parameters-to-token-filter-script-in-elasticsearch/212255/5 "2020-01-15T12:20:34Z")

</div>

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