Advanced score ScriptPlugin

Hello,

I ve been trying lately to upgrade my MyNativeScriptPlugin from ES 5.6.3 to an advanced script plugin in ES 7.4.0 using scriptEngine instead of NativeScriptFactory.

I ve followed this guide :
https://www.elastic.co/guide/en/elasticsearch/reference/7.4/modules-scripting-engine.html

Until now I ve been succesfully building, deploying and running ES with my new plugin... except that it's not scoring my document.
I'm very new to ES so, maybe I'm missing something very obvious.

When I try a simple POST /_search
I can see 2 hits

But there is no hit when I try
POST /mytype/_search
{
"size":20,
"query": {
"function_score": {
"query": {
"match": {
"nom": "xxx"
}
},
"functions":[
{
"filter":{
"match_all":{
"boost":1.0
}
},
"script_score":{
"script":{
"source":"my-source",
"lang":"my-lang",
"params":{
"param1":"1111",
"param2":"2222"
}
}
}
}
]
}
}
}

I see that newInstance is called a few times.
But I'm never entering into the execute method.

This method is supposed to read from documents my fields values and return a custom score.

So my questions are :

  • how to read my documents fields values ?
  • how to call this execute method?

Thanks in advance for your reply.

Ok I ve been removing type from my POST request, and now I'm entering into the execute method.

I ve been desperately trying a lot of things until now without suceeding to get my documents fields values,
like :

getDoc().entrySet() = > throwing exception
context.reader().document() => no
context.reader().getSortedSetDocValues("name") => nope
DocValues.getSortedSet(context.reader(), "name") => nope
...

Maybe this can help, my mappings looks like this when I create my template :

....

 "mappings": {
		"date_detection": false,
		"numeric_detection": false,
			"properties": {
				"name": {
					"type": "text",
					"analyzer": "analyzer",
					"norms": false,
					"index_options": "docs",
					"fielddata": true
				},
					"basic_name": {
					"type": "text",
					"analyzer": "basic",
					"norms": false,
					"index_options": "docs",
					"fielddata": true
				},

....

Any hint ?

getDoc().entrySet()

Getting the entrySet of the doc map won't work as we don't allow iterating over all docvalues fields of a doc. Instead, you need to lookup the particular field:

getDoc().get("myfield")

You'll then cast that to the appropriate ScriptDocValues subclass given your field type. However, the mapping examples above show only 2 text fields. Text fields are not stored in doc values. You'll need to add a keyword field if you want to access a string value, or use another field you have with numeric values.

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