groovy.asciidoc 5.1 KB

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