# Loading and Registering Native Scripts

**URL:** <https://discuss.elastic.co/t/loading-and-registering-native-scripts/4666>\
**Category:** Elasticsearch\
**Created:** [June 21, 2011, 1:04am UTC](https://discuss.elastic.co/t/loading-and-registering-native-scripts/4666 "2011-06-21T01:04:04Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![thnguyen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thnguyen/32/3207_2.png) [@thnguyen](https://discuss.elastic.co/u/thnguyen)\
**Post date:** [June 21, 2011, 1:04am UTC](https://discuss.elastic.co/t/loading-and-registering-native-scripts/4666/1 "2011-06-21T01:04:04Z")

</div>

I've created a class com.thomas.ObjectSearchScript that extends  
AbstractFloatSearchScript. The documentation on native scripting  
isn't too clear to me. I assume creating a jar containing just my  
class and placing it into the lib directory will load the class. How  
do I actually register it through settings or in a plugin using  
ScriptModule?

I'd like to eventually be able to use my class by issuing the  
following query:

{  
"query":{  
"custom\_score":{  
"query":{  
"query\_string":{  
"default\_field":"title",  
"query":"grand theft auto"  
}  
},  
"lang":"native",  
"script":"ObjectSearchScript "  
}  
}  
}

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [June 21, 2011, 4:43am UTC](https://discuss.elastic.co/t/loading-and-registering-native-scripts/4666/2 "2011-06-21T04:43:44Z")

</div>

Did you try to give in the query the full classname ? With the package ?

> "script":"com.thomas.ObjectSearchScript "

Hope this helps

David 😉

Le 21 juin 2011 à 03:04, thnguyen [tsxn26@gmail.com](mailto:tsxn26@gmail.com) a écrit :

> I've created a class com.thomas.ObjectSearchScript that extends  
> AbstractFloatSearchScript. The documentation on native scripting  
> isn't too clear to me. I assume creating a jar containing just my  
> class and placing it into the lib directory will load the class. How  
> do I actually register it through settings or in a plugin using  
> ScriptModule?
> 
> I'd like to eventually be able to use my class by issuing the  
> following query:
> 
> {  
> "query":{  
> "custom\_score":{  
> "query":{  
> "query\_string":{  
> "default\_field":"title",  
> "query":"grand theft auto"  
> }  
> },  
> "lang":"native",  
> "script":"ObjectSearchScript "  
> }  
> }  
> }

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [June 21, 2011, 4:46am UTC](https://discuss.elastic.co/t/loading-and-registering-native-scripts/4666/3 "2011-06-21T04:46:06Z")

</div>

Sorry wrong answer :  
Did you put your script in settings ?

Registering them can either be done by settings, for example: script.native.my.type set tosample.MyNativeScriptFactory will register a script named my.

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

> Did you try to give in the query the full classname ? With the package ?
> 
> > "script":"com.thomas.ObjectSearchScript "
> 
> Hope this helps
> 
> David 😉
> 
> Le 21 juin 2011 à 03:04, thnguyen [tsxn26@gmail.com](mailto:tsxn26@gmail.com) a écrit :
> 
> > I've created a class com.thomas.ObjectSearchScript that extends  
> > AbstractFloatSearchScript. The documentation on native scripting  
> > isn't too clear to me. I assume creating a jar containing just my  
> > class and placing it into the lib directory will load the class. How  
> > do I actually register it through settings or in a plugin using  
> > ScriptModule?
> > 
> > I'd like to eventually be able to use my class by issuing the  
> > following query:
> > 
> > {  
> > "query":{  
> > "custom\_score":{  
> > "query":{  
> > "query\_string":{  
> > "default\_field":"title",  
> > "query":"grand theft auto"  
> > }  
> > },  
> > "lang":"native",  
> > "script":"ObjectSearchScript "  
> > }  
> > }  
> > }

---

<div class="post-metadata">

**Author:** ![thnguyen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thnguyen/32/3207_2.png) [@thnguyen](https://discuss.elastic.co/u/thnguyen)\
**Post date:** [June 21, 2011, 6:09pm UTC](https://discuss.elastic.co/t/loading-and-registering-native-scripts/4666/4 "2011-06-21T18:09:49Z")

</div>

I tried that out but the native script cannot be found when issuing  
the query. Here's how I modified my settings:

curl -XPUT '[http://localhost/media/\_settings](http://localhost/media/_settings)' -d '{ "index" :  
{ "script.native.my.type" : "com.thomas.ObjectSearchScript" } }'

Here are what my settings look like after modifying them:

{"media":{"settings":  
{"index.number\_of\_replicas":"1","index.number\_of\_shards":"1","index.index":"media","index.script.native.my.type":"com.thomas.ObjectSearchScript"}}}

Here is my query:

{  
"query":{  
"custom\_score":{  
"query":{  
"query\_string":{  
"default\_field":"title",  
"query":"grand theft auto"  
}  
},  
"lang":"native",  
"script":"my "  
}  
}

BTW, I also created a plugins directory under $ES\_HOME and copied my  
jar to the directory in addition to $ES\_HOME/lib.

On Jun 20, 9:46 pm, David Pilato [da...@pilato.fr](mailto:da...@pilato.fr) wrote:

> Sorry wrong answer :  
> Did you put your script in settings ?
> 
> Registering them can either be done by settings, for example: script.native.my.type set tosample.MyNativeScriptFactory will register a script named my.[Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/modules/scripting.html)
> 
> > Did you try to give in the query the full classname ? With the package ?
> > 
> > > "script":"com.thomas.ObjectSearchScript "
> 
> > Hope this helps
> 
> > David 😉
> 
> > Le 21 juin 2011 à 03:04, thnguyen [tsx...@gmail.com](mailto:tsx...@gmail.com) a écrit :
> 
> > > I've created a class com.thomas.ObjectSearchScript that extends  
> > > AbstractFloatSearchScript. The documentation on native scripting  
> > > isn't too clear to me. I assume creating a jar containing just my  
> > > class and placing it into the lib directory will load the class. How  
> > > do I actually register it through settings or in a plugin using  
> > > ScriptModule?
> 
> > > I'd like to eventually be able to use my class by issuing the  
> > > following query:
> 
> > > {  
> > > "query":{  
> > > "custom\_score":{  
> > > "query":{  
> > > "query\_string":{  
> > > "default\_field":"title",  
> > > "query":"grand theft auto"  
> > > }  
> > > },  
> > > "lang":"native",  
> > > "script":"ObjectSearchScript "  
> > > }  
> > > }  
> > > }

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [June 22, 2011, 7:38pm UTC](https://discuss.elastic.co/t/loading-and-registering-native-scripts/4666/5 "2011-06-22T19:38:36Z")

</div>

It seems that you have a blank after "my" here :  
"lang":"native",  
"script":"my "

Try to remove the blank.

Hope this helps

-----Message d'origine-----  
De : thnguyen [[mailto:tsxn26@gmail.com](mailto:tsxn26@gmail.com)]  
Envoyé : mardi 21 juin 2011 20:10  
À : users  
Objet : Re: Loading and Registering Native Scripts

I tried that out but the native script cannot be found when issuing  
the query. Here's how I modified my settings:

curl -XPUT '[http://localhost/media/\_settings](http://localhost/media/_settings)' -d '{ "index" :  
{ "script.native.my.type" : "com.thomas.ObjectSearchScript" } }'

Here are what my settings look like after modifying them:

{"media":{"settings":  
{"index.number\_of\_replicas":"1","index.number\_of\_shards":"1","index.index":"  
media","index.script.native.my.type":"com.thomas.ObjectSearchScript"}}}

Here is my query:

{  
"query":{  
"custom\_score":{  
"query":{  
"query\_string":{  
"default\_field":"title",  
"query":"grand theft auto"  
}  
},  
"lang":"native",  
"script":"my "  
}  
}

BTW, I also created a plugins directory under $ES\_HOME and copied my  
jar to the directory in addition to $ES\_HOME/lib.

---

<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:02am UTC](https://discuss.elastic.co/t/loading-and-registering-native-scripts/4666/6 "2017-07-06T04:02:56Z")

</div>


