1
0

engine.asciidoc 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. [[modules-scripting-engine]]
  2. == Advanced scripts using script engines
  3. A `ScriptEngine` is a backend for implementing a scripting language. It may also
  4. be used to write scripts that need to use advanced internals of scripting. For example,
  5. a script that wants to use term frequencies while scoring.
  6. The plugin {plugins}/plugin-authors.html[documentation] has more information on
  7. how to write a plugin so that Elasticsearch will properly load it. To register
  8. the `ScriptEngine`, your plugin should implement the `ScriptPlugin` interface
  9. and override the `getScriptEngine(Settings settings)` method.
  10. The following is an example of a custom `ScriptEngine` which uses the language
  11. name `expert_scripts`. It implements a single script called `pure_df` which
  12. may be used as a search script to override each document's score as
  13. the document frequency of a provided term.
  14. ["source","java",subs="attributes,callouts,macros"]
  15. --------------------------------------------------
  16. include-tagged::{plugins-examples-dir}/script-expert-scoring/src/main/java/org/elasticsearch/example/expertscript/ExpertScriptPlugin.java[expert_engine]
  17. --------------------------------------------------
  18. You can execute the script by specifying its `lang` as `expert_scripts`, and the name
  19. of the script as the script source:
  20. [source,js]
  21. --------------------------------------------------
  22. POST /_search
  23. {
  24. "query": {
  25. "function_score": {
  26. "query": {
  27. "match": {
  28. "body": "foo"
  29. }
  30. },
  31. "functions": [
  32. {
  33. "script_score": {
  34. "script": {
  35. "source": "pure_df",
  36. "lang" : "expert_scripts",
  37. "params": {
  38. "field": "body",
  39. "term": "foo"
  40. }
  41. }
  42. }
  43. }
  44. ]
  45. }
  46. }
  47. }
  48. --------------------------------------------------
  49. // CONSOLE
  50. // TEST[skip:we don't have an expert script plugin installed to test this]