Hi Team,
I am writing a custom painless plugin to perform few custom calculations.
I have referred this example and created one (https://github.com/elastic/elasticsearch/tree/master/plugins/examples/painless-whitelist).
I have installed the plugin into elastic search folder directly with respective plugin-description file.
In the log i can see plugin loaded
[2019-02-17T11:47:20,146][INFO ][o.e.p.PluginsService ] [QxGCpoN] loaded plugin [whitelist-maven]
But the class i created extending PainlessExtension is not loaded(Kept a log in static block to verify).
When i try to use the class i get the below error.
"script": " double value = params.a * params.b / _score;\n double value1 = value * 2;\n String first_nm = doc['first_nm'].toString();\n double value2 = Math.log(first_nm.length());\n def e = new ExampleWhitelistedClass(2,3);\n int x = e.publicMember + e.getPrivateMemberAccessor\n return x + value2 / _score;",
"lang": "painless",
"caused_by": {
"type": "illegal_argument_exception",
"reason": "invalid sequence of tokens near ['ExampleWhitelistedClass'].",
"caused_by": {
"type": "no_viable_alt_exception",
"reason": null
}
}
I am using elastic search version 6.6.0
Can you please check and let me know what am i doing wrong.
Script :
POST _scripts/first_script
{
"script": {
"lang": "painless",
"source": """
double value = params.a * params.b / _score;
double value1 = value * 2;
String first_nm = doc['first_nm'].toString();
double value2 = Math.log(first_nm.length());
def e = new ExampleWhitelistedClass(2,3);
int x = e.publicMember + e.getPrivateMemberAccessor
return x + value2 / _score;
"""
}
}
Query:
{
"query": {
"function_score": {
"query": {
"match": {
"full_text": {
"query": "Rajendra",
"fuzziness": "AUTO"
}
}
},
"script_score": {
"script": {
"id": "first_script",
"params": {
"a": 3,
"b": 1.2
}
}
}
}
}
}