script-query.asciidoc 1.4 KB

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