| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 | [[modules-scripting-engine]]== Advanced scripts using script enginesA `ScriptEngine` is a backend for implementing a scripting language. It may alsobe used to write scripts that need to use advanced internals of scripting. For example,a script that wants to use term frequencies while scoring.The plugin {plugins}/plugin-authors.html[documentation] has more information onhow to write a plugin so that Elasticsearch will properly load it. To registerthe `ScriptEngine`, your plugin should implement the `ScriptPlugin` interfaceand override the `getScriptEngine(Settings settings)` method.The following is an example of a custom `ScriptEngine` which uses the languagename `expert_scripts`. It implements a single script called `pure_df` whichmay be used as a search script to override each document's score asthe document frequency of a provided term.["source","java",subs="attributes,callouts,macros"]--------------------------------------------------include-tagged::{plugins-examples-dir}/script-expert-scoring/src/main/java/org/elasticsearch/example/expertscript/ExpertScriptPlugin.java[expert_engine]--------------------------------------------------You can execute the script by specifying its `lang` as `expert_scripts`, and the nameof the script as the script source:[source,js]--------------------------------------------------POST /_search{  "query": {    "function_score": {      "query": {        "match": {          "body": "foo"        }      },      "functions": [        {          "script_score": {            "script": {                "source": "pure_df",                "lang" : "expert_scripts",                "params": {                    "field": "body",                    "term": "foo"                }            }          }        }      ]    }  }}--------------------------------------------------// CONSOLE// TEST[skip:we don't have an expert script plugin installed to test this]
 |