# Passing parameter to native script

**URL:** <https://discuss.elastic.co/t/passing-parameter-to-native-script/4741>\
**Category:** Elasticsearch\
**Created:** [June 30, 2011, 1:00pm UTC](https://discuss.elastic.co/t/passing-parameter-to-native-script/4741 "2011-06-30T13:00:46Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eugen\_Zagorodniy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/eugen_zagorodniy/32/3190_2.png) [@Eugen\_Zagorodniy](https://discuss.elastic.co/u/Eugen_Zagorodniy)\
**Post date:** [June 30, 2011, 1:00pm UTC](https://discuss.elastic.co/t/passing-parameter-to-native-script/4741/1 "2011-06-30T13:00:46Z")

</div>

Hello!

Is there way to pass parameter to native script? For example, if I  
execute query

{  
"query": {  
"custom\_score": {  
"query": { ... },  
"params" : { "x" : "value" },  
"lang":"native",  
"script":"CustomScript"  
}  
}  
}

- how do I access value of "x" parameter in the native script  
CustomScript?

Thanks!

---

<div class="post-metadata">

**Author:** ![Karussell1](https://avatars.discourse-cdn.com/v4/letter/k/50afbb/32.png) [@Karussell1](https://discuss.elastic.co/u/Karussell1)\
**Post date:** [July 1, 2011, 8:31pm UTC](https://discuss.elastic.co/t/passing-parameter-to-native-script/4741/2 "2011-07-01T20:31:03Z")

</div>

via params:

public ExecutableScript newScript(final Map\<String, Object\> params) {  
return new AbstractFloatSearchScript() {

```
        @Override
        public float runAsFloat() {
            params.get("xy");

```

....  
}}}

On Jun 30, 3:00 pm, Eugen Zagorodniy [e.zagorod...@gmail.com](mailto:e.zagorod...@gmail.com) wrote:

> Hello!
> 
> Is there way to pass parameter to native script? For example, if I  
> execute query
> 
> {  
> "query": {  
> "custom\_score": {  
> "query": { ... },  
> "params" : { "x" : "value" },  
> "lang":"native",  
> "script":"CustomScript"  
> }  
> }
> 
> }
> 
> - how do I access value of "x" parameter in the native script  
> CustomScript?
> 
> Thanks!

---

<div class="post-metadata">

**Author:** ![nachiket](https://avatars.discourse-cdn.com/v4/letter/n/4491bb/32.png) [@nachiket](https://discuss.elastic.co/u/nachiket)\
**Post date:** [July 11, 2011, 3:53am UTC](https://discuss.elastic.co/t/passing-parameter-to-native-script/4741/3 "2011-07-11T03:53:13Z")

</div>

Hi.  
I have a doubt about this.  
Exactly where are we suppose to write this function.  
I mean as we are returning AbstractFloatSearchScript I wrote this  
function as a part of factory class.  
Does this means class returned by my factory is nested class?  
I didn't write Script.class at all.  
My factory class is at [https://gist.github.com/1073346](https://gist.github.com/1073346).  
Is there any mistake, because I am getting this error continously  
git://gist.github.com/1073348.git.  
Can anybody help me to where to include this function?

On Jul 2, 1:31 am, Karussell [tableyourt...@googlemail.com](mailto:tableyourt...@googlemail.com) wrote:

> via params:
> 
> public ExecutableScript newScript(final Map\<String, Object\> params) {  
> return new AbstractFloatSearchScript() {
> 
> ```
> @Override
> public float runAsFloat() {
> params.get("xy");
> 
> ```
> 
> ....
> 
> }}}
> 
> On Jun 30, 3:00 pm, Eugen Zagorodniy [e.zagorod...@gmail.com](mailto:e.zagorod...@gmail.com) wrote:
> 
> > Hello!
> 
> > Is there way to pass parameter tonativescript? For example, if I  
> > execute query
> 
> > {  
> > "query": {  
> > "custom\_score": {  
> > "query": { ... },  
> > "params" : { "x" : "value" },  
> > "lang":"native",  
> > "script":"CustomScript"  
> > }  
> > }
> 
> > }
> 
> > - how do I access value of "x" parameter in thenativescript  
> > CustomScript?
> 
> > Thanks!

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [July 11, 2011, 5:06pm UTC](https://discuss.elastic.co/t/passing-parameter-to-native-script/4741/4 "2011-07-11T17:06:06Z")

</div>

It can be an inner class, or another class defined, it does not matter. Can you post your config based on the same code you provided?

On Monday, July 11, 2011 at 6:53 AM, nachiket bhagwat wrote:

> Hi.  
> I have a doubt about this.  
> Exactly where are we suppose to write this function.  
> I mean as we are returning AbstractFloatSearchScript I wrote this  
> function as a part of factory class.  
> Does this means class returned by my factory is nested class?  
> I didn't write Script.class at all.  
> My factory class is at [https://gist.github.com/1073346](https://gist.github.com/1073346).  
> Is there any mistake, because I am getting this error continously  
> git://gist.github.com/1073348.git ([http://gist.github.com/1073348.git](http://gist.github.com/1073348.git)).  
> Can anybody help me to where to include this function?
> 
> On Jul 2, 1:31 am, Karussell \<[tableyourt...@googlemail.com](mailto:tableyourt...@googlemail.com) ([http://googlemail.com](http://googlemail.com))\> wrote:
> 
> > via params:
> > 
> > public ExecutableScript newScript(final Map\<String, Object\> params) {  
> > return new AbstractFloatSearchScript() {
> > 
> > @Override  
> > public float runAsFloat() {  
> > params.get("xy");  
> > ....
> > 
> > }}}
> > 
> > On Jun 30, 3:00 pm, Eugen Zagorodniy \<[e.zagorod...@gmail.com](mailto:e.zagorod...@gmail.com) ([http://gmail.com](http://gmail.com))\> wrote:
> > 
> > > Hello!
> > 
> > > Is there way to pass parameter tonativescript? For example, if I  
> > > execute query
> > 
> > > {  
> > > "query": {  
> > > "custom\_score": {  
> > > "query": { ... },  
> > > "params" : { "x" : "value" },  
> > > "lang":"native",  
> > > "script":"CustomScript"  
> > > }  
> > > }
> > 
> > > }
> > 
> > > - how do I access value of "x" parameter in thenativescript  
> > > CustomScript?
> > 
> > > Thanks!

---

<div class="post-metadata">

**Author:** ![nachiket](https://avatars.discourse-cdn.com/v4/letter/n/4491bb/32.png) [@nachiket](https://discuss.elastic.co/u/nachiket)\
**Post date:** [July 13, 2011, 7:58am UTC](https://discuss.elastic.co/t/passing-parameter-to-native-script/4741/5 "2011-07-13T07:58:21Z")

</div>

My Config file.  
script.native.foo.type:  
in.vedantu.search.scripts.SampleScriptFactory.

Actually I am able to access params in newScript function of  
SampleScriptFactory.  
But if I don't create SampleScript.java, then I get error I mentioned  
earlier.  
If I create SampleSctipt.java then I can't access params.

On Jul 11, 10:06 pm, Shay Banon [shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) wrote:

> It can be an inner class, or another class defined, it does not matter. Can you post your config based on the same code you provided?
> 
> On Monday, July 11, 2011 at 6:53 AM, nachiket bhagwat wrote:
> 
> > Hi.  
> > I have a doubt about this.  
> > Exactly where are we suppose to write this function.  
> > I mean as we are returning AbstractFloatSearchScript I wrote this  
> > function as a part of factory class.  
> > Does this means class returned by my factory is nested class?  
> > I didn't write Script.class at all.  
> > My factory class is athttps://gist.github.com/1073346.  
> > Is there any mistake, because I am getting this error continously  
> > git://gist.github.com/1073348.git ([http://gist.github.com/1073348.git](http://gist.github.com/1073348.git)).  
> > Can anybody help me to where to include this function?
> 
> > On Jul 2, 1:31 am, Karussell \<[tableyourt...@googlemail.com](mailto:tableyourt...@googlemail.com) ([http://googlemail.com](http://googlemail.com))\> wrote:
> > 
> > > via params:
> 
> > > public ExecutableScript newScript(final Map\<String, Object\> params) {  
> > > return new AbstractFloatSearchScript() {
> 
> > > @Override  
> > > public float runAsFloat() {  
> > > params.get("xy");  
> > > ....
> 
> > > }}}
> 
> > > On Jun 30, 3:00 pm, Eugen Zagorodniy \<[e.zagorod...@gmail.com](mailto:e.zagorod...@gmail.com) ([http://gmail.com](http://gmail.com))\> wrote:
> 
> > > > Hello!
> 
> > > > Is there way to pass parameter tonativescript? For example, if I  
> > > > execute query
> 
> > > > {  
> > > > "query": {  
> > > > "custom\_score": {  
> > > > "query": { ... },  
> > > > "params" : { "x" : "value" },  
> > > > "lang":"native",  
> > > > "script":"CustomScript"  
> > > > }  
> > > > }
> 
> > > > }
> 
> > > > - how do I access value of "x" parameter in thenativescript  
> > > > CustomScript?
> 
> > > > Thanks!

---

<div class="post-metadata">

**Author:** ![nachiket](https://avatars.discourse-cdn.com/v4/letter/n/4491bb/32.png) [@nachiket](https://discuss.elastic.co/u/nachiket)\
**Post date:** [July 14, 2011, 11:03am UTC](https://discuss.elastic.co/t/passing-parameter-to-native-script/4741/6 "2011-07-14T11:03:33Z")

</div>

Hi. Can anybody help on above issue ?

On Jul 13, 12:58 pm, nachiket bhagwat [nachiketbhag...@gmail.com](mailto:nachiketbhag...@gmail.com)  
wrote:

> My Config file.script.native.foo.type:  
> in.vedantu.search.scripts.SampleScriptFactory.
> 
> Actually I am able to access params in newScript function of  
> SampleScriptFactory.  
> But if I don't create SampleScript.java, then I get error I mentioned  
> earlier.  
> If I create SampleSctipt.java then I can't access params.
> 
> On Jul 11, 10:06 pm, Shay Banon [shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) wrote:
> 
> > It can be an inner class, or another class defined, it does not matter. Can you post your config based on the same code you provided?
> 
> > On Monday, July 11, 2011 at 6:53 AM, nachiket bhagwat wrote:
> > 
> > > Hi.  
> > > I have a doubt about this.  
> > > Exactly where are we suppose to write this function.  
> > > I mean as we are returning AbstractFloatSearchScript I wrote this  
> > > function as a part of factory class.  
> > > Does this means class returned by my factory is nested class?  
> > > I didn't writeScript.class at all.  
> > > My factory class is athttps://gist.github.com/1073346.  
> > > Is there any mistake, because I am getting this error continously  
> > > git://gist.github.com/1073348.git ([http://gist.github.com/1073348.git](http://gist.github.com/1073348.git)).  
> > > Can anybody help me to where to include this function?
> 
> > > On Jul 2, 1:31 am, Karussell \<[tableyourt...@googlemail.com](mailto:tableyourt...@googlemail.com) ([http://googlemail.com](http://googlemail.com))\> wrote:
> > > 
> > > > via params:
> 
> > > > public ExecutableScript newScript(final Map\<String, Object\> params) {  
> > > > return new AbstractFloatSearchScript() {
> 
> > > > @Override  
> > > > public float runAsFloat() {  
> > > > params.get("xy");  
> > > > ....
> 
> > > > }}}
> 
> > > > On Jun 30, 3:00 pm, Eugen Zagorodniy \<[e.zagorod...@gmail.com](mailto:e.zagorod...@gmail.com) ([http://gmail.com](http://gmail.com))\> wrote:
> 
> > > > > Hello!
> 
> > > > > Is there way to passparametertonativescript? For example, if I  
> > > > > execute query
> 
> > > > > {  
> > > > > "query": {  
> > > > > "custom\_score": {  
> > > > > "query": { ... },  
> > > > > "params" : { "x" : "value" },  
> > > > > "lang":"native",  
> > > > > "script":"CustomScript"  
> > > > > }  
> > > > > }
> 
> > > > > }
> 
> > > > > - how do I access value of "x"parameterin thenativescript  
> > > > > CustomScript?
> 
> > > > > Thanks!

---

<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:** [July 6, 2017, 4:00am UTC](https://discuss.elastic.co/t/passing-parameter-to-native-script/4741/7 "2017-07-06T04:00:41Z")

</div>


