groovy.asciidoc 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. [[modules-scripting-groovy]]
  2. === Groovy Scripting Language
  3. deprecated[5.0.0,Groovy will be replaced by the new scripting language <<modules-scripting-painless, `Painless`>>]
  4. Groovy is available in Elasticsearch by default. Although
  5. limited by the <<java-security-manager,Java Security Manager>>, it is not a
  6. sandboxed language and only `file` scripts may be used by default.
  7. Enabling `inline` or `stored` Groovy scripting is a security risk and should
  8. only be considered if your Elasticsearch cluster is protected from the outside
  9. world. Even a simple `while (true) { }` loop could behave as a denial-of-
  10. service attack on your cluster.
  11. See <<modules-scripting-security, Scripting and Security>> for details
  12. on security issues with scripts, including how to customize class
  13. whitelisting.
  14. [float]
  15. === Doc value properties and methods
  16. Doc values in Groovy support the following properties and methods (depending
  17. on the underlying field type):
  18. `doc['field_name'].value`::
  19. The native value of the field. For example, if its a short type, it will be short.
  20. `doc['field_name'].values`::
  21. The native array values of the field. For example, if its a short type,
  22. it will be short[]. Remember, a field can have several values within a
  23. single doc. Returns an empty array if the field has no values.
  24. `doc['field_name'].empty`::
  25. A boolean indicating if the field has no values within the doc.
  26. `doc['field_name'].lat`::
  27. The latitude of a geo point type, or `null`.
  28. `doc['field_name'].lon`::
  29. The longitude of a geo point type, or `null`.
  30. `doc['field_name'].lats`::
  31. The latitudes of a geo point type, or an empty array.
  32. `doc['field_name'].lons`::
  33. The longitudes of a geo point type, or an empty array.
  34. `doc['field_name'].arcDistance(lat, lon)`::
  35. The `arc` distance (in meters) of this geo point field from the provided lat/lon.
  36. `doc['field_name'].arcDistanceWithDefault(lat, lon, default)`::
  37. The `arc` distance (in meters) of this geo point field from the provided lat/lon with a default value
  38. for empty fields.
  39. `doc['field_name'].planeDistance(lat, lon)`::
  40. The `plane` distance (in meters) of this geo point field from the provided lat/lon.
  41. `doc['field_name'].planeDistanceWithDefault(lat, lon, default)`::
  42. The `plane` distance (in meters) of this geo point field from the provided lat/lon with a default value
  43. for empty fields.
  44. `doc['field_name'].geohashDistance(geohash)`::
  45. The `arc` distance (in meters) of this geo point field from the provided geohash.
  46. `doc['field_name'].geohashDistanceWithDefault(geohash, default)`::
  47. The `arc` distance (in meters) of this geo point field from the provided geohash with a default value
  48. for empty fields.
  49. [float]
  50. === Groovy Built In Functions
  51. There are several built in functions that can be used within scripts.
  52. They include:
  53. [cols="<,<",options="header",]
  54. |=======================================================================
  55. |Function |Description
  56. |`sin(a)` |Returns the trigonometric sine of an angle.
  57. |`cos(a)` |Returns the trigonometric cosine of an angle.
  58. |`tan(a)` |Returns the trigonometric tangent of an angle.
  59. |`asin(a)` |Returns the arc sine of a value.
  60. |`acos(a)` |Returns the arc cosine of a value.
  61. |`atan(a)` |Returns the arc tangent of a value.
  62. |`toRadians(angdeg)` |Converts an angle measured in degrees to an
  63. approximately equivalent angle measured in radians
  64. |`toDegrees(angrad)` |Converts an angle measured in radians to an
  65. approximately equivalent angle measured in degrees.
  66. |`exp(a)` |Returns Euler's number _e_ raised to the power of value.
  67. |`log(a)` |Returns the natural logarithm (base _e_) of a value.
  68. |`log10(a)` |Returns the base 10 logarithm of a value.
  69. |`sqrt(a)` |Returns the correctly rounded positive square root of a
  70. value.
  71. |`cbrt(a)` |Returns the cube root of a double value.
  72. |`IEEEremainder(f1, f2)` |Computes the remainder operation on two
  73. arguments as prescribed by the IEEE 754 standard.
  74. |`ceil(a)` |Returns the smallest (closest to negative infinity) value
  75. that is greater than or equal to the argument and is equal to a
  76. mathematical integer.
  77. |`floor(a)` |Returns the largest (closest to positive infinity) value
  78. that is less than or equal to the argument and is equal to a
  79. mathematical integer.
  80. |`rint(a)` |Returns the value that is closest in value to the argument
  81. and is equal to a mathematical integer.
  82. |`atan2(y, x)` |Returns the angle _theta_ from the conversion of
  83. rectangular coordinates (_x_, _y_) to polar coordinates (r,_theta_).
  84. |`pow(a, b)` |Returns the value of the first argument raised to the
  85. power of the second argument.
  86. |`round(a)` |Returns the closest _int_ to the argument.
  87. |`random()` |Returns a random _double_ value.
  88. |`abs(a)` |Returns the absolute value of a value.
  89. |`max(a, b)` |Returns the greater of two values.
  90. |`min(a, b)` |Returns the smaller of two values.
  91. |`ulp(d)` |Returns the size of an ulp of the argument.
  92. |`signum(d)` |Returns the signum function of the argument.
  93. |`sinh(x)` |Returns the hyperbolic sine of a value.
  94. |`cosh(x)` |Returns the hyperbolic cosine of a value.
  95. |`tanh(x)` |Returns the hyperbolic tangent of a value.
  96. |`hypot(x, y)` |Returns sqrt(_x2_ + _y2_) without intermediate overflow
  97. or underflow.
  98. |=======================================================================