Loading and Registering Native Scripts


(thnguyen) #1

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 "
}
}
}


(David Pilato) #2

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

"script":"com.thomas.ObjectSearchScript "

Hope this helps

David :wink:

Le 21 juin 2011 à 03:04, thnguyen 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 "
}
}
}


(David Pilato) #3

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.
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 :wink:

Le 21 juin 2011 à 03:04, thnguyen 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 "
}
}
}


(thnguyen) #4

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' -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 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.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 :wink:

Le 21 juin 2011 à 03:04, thnguyen 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 "
}
}
}


(David Pilato) #5

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]
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' -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.


(system) #6