script-query.asciidoc 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. GET /_search
  9. {
  10. "query": {
  11. "bool" : {
  12. "must" : {
  13. "script" : {
  14. "script" : "doc['num1'].value > 1"
  15. }
  16. }
  17. }
  18. }
  19. }
  20. ----------------------------------------------
  21. // CONSOLE
  22. [float]
  23. ==== Custom Parameters
  24. Scripts are compiled and cached for faster execution. If the same script
  25. can be used, just with different parameters provider, it is preferable
  26. to use the ability to pass parameters to the script itself, for example:
  27. [source,js]
  28. ----------------------------------------------
  29. GET /_search
  30. {
  31. "query": {
  32. "bool" : {
  33. "must" : {
  34. "script" : {
  35. "script" : {
  36. "inline" : "doc['num1'].value > param1",
  37. "params" : {
  38. "param1" : 5
  39. }
  40. }
  41. }
  42. }
  43. }
  44. }
  45. }
  46. ----------------------------------------------
  47. // CONSOLE