New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Scripting: Replace advanced and native scripts with ScriptEngine docs #24603
Changes from all commits
7218d7d
b88a434
adf95e6
a8c326d
1070eb3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
[[modules-scripting-engine]] | ||
=== Advanced scripts using script engines | ||
|
||
A `ScriptEngine` is a backend for implementing a scripting language. It may also | ||
be 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 on | ||
how to write a plugin so that Elasticsearch will properly load it. To register | ||
the `ScriptEngine`, your plugin should implement the `ScriptPlugin` interface | ||
and override the `getScriptEngine(Settings settings)` method. | ||
|
||
The following is an example of a custom `ScriptEngine` which uses the language | ||
name `expert_scripts`. It implements a single script called `pure_df` which | ||
may be used as a search script to override each document's score as | ||
the document frequency of a provided term. | ||
|
||
["source","java",subs="attributes,callouts,macros"] | ||
-------------------------------------------------- | ||
include-tagged::{docdir}/../../plugins/examples/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 name | ||
of the script as the the script source: | ||
|
||
|
||
[source,js] | ||
-------------------------------------------------- | ||
POST /_search | ||
{ | ||
"query": { | ||
"function_score": { | ||
"query": { | ||
"match": { | ||
"body": "foo" | ||
} | ||
}, | ||
"functions": [ | ||
{ | ||
"script_score": { | ||
"script": { | ||
"inline": "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] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I mean, we totally could though. We already install all the plugins, I think we'd just need to fix the loop we use for it and this'd be installed too. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could, but I'd rather leave that as a separate issue. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We install all the other plugins for these tests so I think this would be the PR to add it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1