script-query.asciidoc 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. [[query-dsl-script-query]]
  2. === Script Query
  3. A query allowing to define
  4. <<modules-scripting,scripts>> as queries. They are typically used in a filter
  5. context, for example:
  6. [source,js]
  7. ----------------------------------------------
  8. "bool" : {
  9. "must" : {
  10. ...
  11. },
  12. "filter" : {
  13. "script" : {
  14. "script" : "doc['num1'].value > 1"
  15. }
  16. }
  17. }
  18. ----------------------------------------------
  19. [float]
  20. ==== Custom Parameters
  21. Scripts are compiled and cached for faster execution. If the same script
  22. can be used, just with different parameters provider, it is preferable
  23. to use the ability to pass parameters to the script itself, for example:
  24. [source,js]
  25. ----------------------------------------------
  26. "bool" : {
  27. "must" : {
  28. ...
  29. },
  30. "filter" : {
  31. "script" : {
  32. "script" : {
  33. "inline" : "doc['num1'].value > param1"
  34. "params" : {
  35. "param1" : 5
  36. }
  37. }
  38. }
  39. }
  40. }
  41. ----------------------------------------------