# Advanced score ScriptPlugin

**URL:** <https://discuss.elastic.co/t/advanced-score-scriptplugin/204891>\
**Category:** Elasticsearch\
**Created:** [October 23, 2019, 2:14pm UTC](https://discuss.elastic.co/t/advanced-score-scriptplugin/204891 "2019-10-23T14:14:05Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![idan13](https://avatars.discourse-cdn.com/v4/letter/i/d9b06d/32.png) [@idan13](https://discuss.elastic.co/u/idan13)\
**Post date:** [October 23, 2019, 2:14pm UTC](https://discuss.elastic.co/t/advanced-score-scriptplugin/204891/1 "2019-10-23T14:14:05Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![idan13](https://avatars.discourse-cdn.com/v4/letter/i/d9b06d/32.png) [@idan13](https://discuss.elastic.co/u/idan13)\
**Post date:** [October 25, 2019, 2:38pm UTC](https://discuss.elastic.co/t/advanced-score-scriptplugin/204891/2 "2019-10-25T14:38:16Z")

</div>

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 ?

---

<div class="post-metadata">

**Author:** ![rjernst](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rjernst/32/6363_2.png) [@rjernst](https://discuss.elastic.co/u/rjernst)\
**Post date:** [October 25, 2019, 9:45pm UTC](https://discuss.elastic.co/t/advanced-score-scriptplugin/204891/3 "2019-10-25T21:45:56Z")

</div>

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

```auto
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.

---

<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:** [November 22, 2019, 9:46pm UTC](https://discuss.elastic.co/t/advanced-score-scriptplugin/204891/4 "2019-11-22T21:46:00Z")

</div>

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