scripting.asciidoc 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670
  1. [[modules-scripting]]
  2. == Scripting
  3. The scripting module allows to use scripts in order to evaluate custom
  4. expressions. For example, scripts can be used to return "script fields"
  5. as part of a search request, or can be used to evaluate a custom score
  6. for a query and so on.
  7. The scripting module uses by default http://groovy.codehaus.org/[groovy]
  8. (previously http://mvel.codehaus.org/[mvel] in 1.3.x and earlier) as the
  9. scripting language with some extensions. Groovy is used since it is extremely
  10. fast and very simple to use.
  11. .Groovy dynamic scripting disabled by default from v1.4.3
  12. [IMPORTANT]
  13. ===================================================
  14. Elasticsearch versions 1.3.0-1.3.7 and 1.4.0-1.4.2 have a vulnerability in the
  15. Groovy scripting engine. The vulnerability allows an attacker to construct
  16. Groovy scripts that escape the sandbox and execute shell commands as the user
  17. running the Elasticsearch Java VM.
  18. If you are running a vulnerable version of Elasticsearch, you should either
  19. upgrade to at least v1.3.8 or v1.4.3, or disable dynamic Groovy scripts by
  20. adding this setting to the `config/elasticsearch.yml` file in all nodes in the
  21. cluster:
  22. [source,yaml]
  23. -----------------------------------
  24. script.groovy.sandbox.enabled: false
  25. -----------------------------------
  26. This will turn off the Groovy sandbox, thus preventing dynamic Groovy scripts
  27. from being accepted as part of a request or retrieved from the special
  28. `.scripts` index. You will still be able to use Groovy scripts stored in files
  29. in the `config/scripts/` directory on every node.
  30. To convert an inline script to a file, take this simple script
  31. as an example:
  32. [source,json]
  33. -----------------------------------
  34. GET /_search
  35. {
  36. "script_fields": {
  37. "my_field": {
  38. "script": "1 + my_var",
  39. "params": {
  40. "my_var": 2
  41. }
  42. }
  43. }
  44. }
  45. -----------------------------------
  46. Save the contents of the script as a file called `config/scripts/my_script.groovy`
  47. on every data node in the cluster:
  48. [source,js]
  49. -----------------------------------
  50. 1 + my_var
  51. -----------------------------------
  52. Now you can access the script by file name (without the extension):
  53. [source,json]
  54. -----------------------------------
  55. GET /_search
  56. {
  57. "script_fields": {
  58. "my_field": {
  59. "script_file": "my_test",
  60. "params": {
  61. "my_var": 2
  62. }
  63. }
  64. }
  65. }
  66. -----------------------------------
  67. ===================================================
  68. Additional `lang` plugins are provided to allow to execute scripts in
  69. different languages. All places where a `script` parameter can be used, a `lang` parameter
  70. (on the same level) can be provided to define the language of the
  71. script. The following are the supported scripting languages:
  72. [cols="<,<,<",options="header",]
  73. |=======================================================================
  74. |Language |Sandboxed |Required plugin
  75. |groovy |no |built-in
  76. |expression |yes |built-in
  77. |mustache |yes |built-in
  78. |mvel |no |https://github.com/elastic/elasticsearch-lang-mvel[elasticsearch-lang-mvel]
  79. |javascript |no |https://github.com/elastic/elasticsearch-lang-javascript[elasticsearch-lang-javascript]
  80. |python |no |https://github.com/elastic/elasticsearch-lang-python[elasticsearch-lang-python]
  81. |=======================================================================
  82. To increase security, Elasticsearch does not allow you to specify scripts for
  83. non-sandboxed languages with a request. Instead, scripts must be placed in the
  84. `scripts` directory inside the configuration directory (the directory where
  85. elasticsearch.yml is). Scripts placed into this directory will automatically be
  86. picked up and be available to be used. Once a script has been placed in this
  87. directory, it can be referenced by name. For example, a script called
  88. `calculate-score.groovy` can be referenced in a request like this:
  89. [source,sh]
  90. --------------------------------------------------
  91. $ tree config
  92. config
  93. ├── elasticsearch.yml
  94. ├── logging.yml
  95. └── scripts
  96. └── calculate-score.groovy
  97. --------------------------------------------------
  98. [source,sh]
  99. --------------------------------------------------
  100. $ cat config/scripts/calculate-score.groovy
  101. log(_score * 2) + my_modifier
  102. --------------------------------------------------
  103. [source,js]
  104. --------------------------------------------------
  105. curl -XPOST localhost:9200/_search -d '{
  106. "query": {
  107. "function_score": {
  108. "query": {
  109. "match": {
  110. "body": "foo"
  111. }
  112. },
  113. "functions": [
  114. {
  115. "script_score": {
  116. "lang": "groovy",
  117. "script_file": "calculate-score",
  118. "params": {
  119. "my_modifier": 8
  120. }
  121. }
  122. }
  123. ]
  124. }
  125. }
  126. }'
  127. --------------------------------------------------
  128. The name of the script is derived from the hierarchy of directories it
  129. exists under, and the file name without the lang extension. For example,
  130. a script placed under `config/scripts/group1/group2/test.py` will be
  131. named `group1_group2_test`.
  132. [float]
  133. === Indexed Scripts
  134. Elasticsearch allows you to store scripts in an internal index known as
  135. `.scripts` and reference them by id. There are REST endpoints to manage
  136. indexed scripts as follows:
  137. Requests to the scripts endpoint look like :
  138. [source,js]
  139. -----------------------------------
  140. /_scripts/{lang}/{id}
  141. -----------------------------------
  142. Where the `lang` part is the language the script is in and the `id` part is the id
  143. of the script. In the `.scripts` index the type of the document will be set to the `lang`.
  144. [source,js]
  145. -----------------------------------
  146. curl -XPOST localhost:9200/_scripts/groovy/indexedCalculateScore -d '{
  147. "script": "log(_score * 2) + my_modifier"
  148. }'
  149. -----------------------------------
  150. This will create a document with id: `indexedCalculateScore` and type: `groovy` in the
  151. `.scripts` index. The type of the document is the language used by the script.
  152. This script can be accessed at query time by appending `_id` to
  153. the script parameter and passing the script id. So `script` becomes `script_id`.:
  154. [source,js]
  155. --------------------------------------------------
  156. curl -XPOST localhost:9200/_search -d '{
  157. "query": {
  158. "function_score": {
  159. "query": {
  160. "match": {
  161. "body": "foo"
  162. }
  163. },
  164. "functions": [
  165. {
  166. "script_score": {
  167. "script_id": "indexedCalculateScore",
  168. "lang" : "groovy",
  169. "params": {
  170. "my_modifier": 8
  171. }
  172. }
  173. }
  174. ]
  175. }
  176. }
  177. }'
  178. --------------------------------------------------
  179. The script can be viewed by:
  180. [source,js]
  181. -----------------------------------
  182. curl -XGET localhost:9200/_scripts/groovy/indexedCalculateScore
  183. -----------------------------------
  184. This is rendered as:
  185. [source,js]
  186. -----------------------------------
  187. '{
  188. "script": "log(_score * 2) + my_modifier"
  189. }'
  190. -----------------------------------
  191. Indexed scripts can be deleted by:
  192. [source,js]
  193. -----------------------------------
  194. curl -XDELETE localhost:9200/_scripts/groovy/indexedCalculateScore
  195. -----------------------------------
  196. [float]
  197. [[enable-dynamic-scripting]]
  198. === Enabling dynamic scripting
  199. We recommend running Elasticsearch behind an application or proxy, which
  200. protects Elasticsearch from the outside world. If users are allowed to run
  201. inline scripts (even in a search request) or indexed scripts, then they have
  202. the same access to your box as the user that Elasticsearch is running as. For
  203. this reason dynamic scripting is allowed only for sandboxed languages by default.
  204. First, you should not run Elasticsearch as the `root` user, as this would allow
  205. a script to access or do *anything* on your server, without limitations. Second,
  206. you should not expose Elasticsearch directly to users, but instead have a proxy
  207. application inbetween. If you *do* intend to expose Elasticsearch directly to
  208. your users, then you have to decide whether you trust them enough to run scripts
  209. on your box or not.
  210. deprecated[1.6.0, the `script.disable_dynamic` setting is deprecated in favour of fine-grained settings described as follows]
  211. It is possible to enable scripts based on their source, for
  212. every script engine, through the following settings that need to be added to the
  213. `config/elasticsearch.yml` file on every node.
  214. [source,yaml]
  215. -----------------------------------
  216. script.inline: on
  217. script.indexed: on
  218. -----------------------------------
  219. While this still allows execution of named scripts provided in the config, or
  220. _native_ Java scripts registered through plugins, it also allows users to run
  221. arbitrary scripts via the API. Instead of sending the name of the file as the
  222. script, the body of the script can be sent instead or retrieved from the
  223. `.scripts` indexed if previously stored.
  224. There are three possible configuration values for any of the fine-grained
  225. script settings:
  226. [cols="<,<",options="header",]
  227. |=======================================================================
  228. |Value |Description
  229. | `off` |scripting is turned off completely, in the context of the setting being set.
  230. | `on` |scripting is turned on, in the context of the setting being set.
  231. | `sandbox` |scripts may be executed only for languages that are sandboxed
  232. |=======================================================================
  233. The default values are the following:
  234. [source,yaml]
  235. -----------------------------------
  236. script.inline: sandbox
  237. script.indexed: sandbox
  238. script.file: on
  239. -----------------------------------
  240. NOTE: Global scripting settings affect the `mustache` scripting language.
  241. <<search-template,Search templates>> internally use the `mustache` language,
  242. and will still be enabled by default as the `mustache` engine is sandboxed,
  243. but they will be enabled/disabled according to fine-grained settings
  244. specified in `elasticsearch.yml`.
  245. It is also possible to control which operations can execute scripts. The
  246. supported operations are:
  247. [cols="<,<",options="header",]
  248. |=======================================================================
  249. |Value |Description
  250. | `aggs` |Aggregations (wherever they may be used)
  251. | `mapping` |Mappings (script transform feature)
  252. | `search` |Search api, Percolator api and Suggester api (e.g filters, script_fields)
  253. | `update` |Update api
  254. |=======================================================================
  255. The following example disables scripting for `update` and `mapping` operations,
  256. regardless of the script source, for any engine. Scripts can still be
  257. executed from sandboxed languages as part of `aggregations` and `search`
  258. operations though, as the above defaults still get applied.
  259. [source,yaml]
  260. -----------------------------------
  261. script.update: off
  262. script.mapping: off
  263. -----------------------------------
  264. Generic settings get applied in order, operation based ones have precedence
  265. over source based ones. Language specific settings are supported too. They
  266. need to be prefixed with the `script.engine.<engine>` prefix and have
  267. precedence over any other generic settings.
  268. [source,yaml]
  269. -----------------------------------
  270. script.engine.groovy.file.aggs: on
  271. script.engine.groovy.file.mapping: on
  272. script.engine.groovy.file.search: on
  273. script.engine.groovy.file.update: on
  274. script.engine.groovy.indexed.aggs: on
  275. script.engine.groovy.indexed.mapping: off
  276. script.engine.groovy.indexed.search: on
  277. script.engine.groovy.indexed.update: off
  278. script.engine.groovy.inline.aggs: on
  279. script.engine.groovy.inline.mapping: off
  280. script.engine.groovy.inline.search: off
  281. script.engine.groovy.inline.update: off
  282. -----------------------------------
  283. [float]
  284. === Default Scripting Language
  285. The default scripting language (assuming no `lang` parameter is provided) is
  286. `groovy`. In order to change it, set the `script.default_lang` to the
  287. appropriate language.
  288. [float]
  289. === Groovy Sandboxing
  290. Elasticsearch sandboxes Groovy scripts that are compiled and executed in order
  291. to ensure they don't perform unwanted actions. There are a number of options
  292. that can be used for configuring this sandbox:
  293. `script.groovy.sandbox.receiver_whitelist`::
  294. Comma-separated list of string classes for objects that may have methods
  295. invoked.
  296. `script.groovy.sandbox.package_whitelist`::
  297. Comma-separated list of packages under which new objects may be constructed.
  298. `script.groovy.sandbox.class_whitelist`::
  299. Comma-separated list of classes that are allowed to be constructed.
  300. `script.groovy.sandbox.method_blacklist`::
  301. Comma-separated list of methods that are never allowed to be invoked,
  302. regardless of target object.
  303. `script.groovy.sandbox.enabled`::
  304. Flag to enable the sandbox (defaults to `false` added[v1.4.3] meaning the sandbox is
  305. disabled).
  306. When specifying whitelist or blacklist settings for the groovy sandbox, all
  307. options replace the current whitelist, they are not additive.
  308. [float]
  309. === Automatic Script Reloading
  310. The `config/scripts` directory is scanned periodically for changes.
  311. New and changed scripts are reloaded and deleted script are removed
  312. from preloaded scripts cache. The reload frequency can be specified
  313. using `watcher.interval` setting, which defaults to `60s`.
  314. To disable script reloading completely set `script.auto_reload_enabled`
  315. to `false`.
  316. [[native-java-scripts]]
  317. [float]
  318. === Native (Java) Scripts
  319. Even though `groovy` is pretty fast, this allows to register native Java based
  320. scripts for faster execution.
  321. In order to allow for scripts, the `NativeScriptFactory` needs to be
  322. implemented that constructs the script that will be executed. There are
  323. two main types, one that extends `AbstractExecutableScript` and one that
  324. extends `AbstractSearchScript` (probably the one most users will extend,
  325. with additional helper classes in `AbstractLongSearchScript`,
  326. `AbstractDoubleSearchScript`, and `AbstractFloatSearchScript`).
  327. Registering them can either be done by settings, for example:
  328. `script.native.my.type` set to `sample.MyNativeScriptFactory` will
  329. register a script named `my`. Another option is in a plugin, access
  330. `ScriptModule` and call `registerScript` on it.
  331. Executing the script is done by specifying the `lang` as `native`, and
  332. the name of the script as the `script`.
  333. Note, the scripts need to be in the classpath of elasticsearch. One
  334. simple way to do it is to create a directory under plugins (choose a
  335. descriptive name), and place the jar / classes files there. They will be
  336. automatically loaded.
  337. [float]
  338. === Lucene Expressions Scripts
  339. [WARNING]
  340. ========================
  341. This feature is *experimental* and subject to change in future versions.
  342. ========================
  343. Lucene's expressions module provides a mechanism to compile a
  344. `javascript` expression to bytecode. This allows very fast execution,
  345. as if you had written a `native` script. Expression scripts can be
  346. used in `script_score`, `script_fields`, sort scripts and numeric aggregation scripts.
  347. See the link:http://lucene.apache.org/core/4_9_0/expressions/index.html?org/apache/lucene/expressions/js/package-summary.html[expressions module documentation]
  348. for details on what operators and functions are available.
  349. Variables in `expression` scripts are available to access:
  350. * Single valued document fields, e.g. `doc['myfield'].value`
  351. * Parameters passed into the script, e.g. `mymodifier`
  352. * The current document's score, `_score` (only available when used in a `script_score`)
  353. There are a few limitations relative to other script languages:
  354. * Only numeric fields may be accessed
  355. * Stored fields are not available
  356. * If a field is sparse (only some documents contain a value), documents missing the field will have a value of `0`
  357. [float]
  358. === Score
  359. In all scripts that can be used in aggregations, the current
  360. document's score is accessible in `_score`.
  361. [float]
  362. === Computing scores based on terms in scripts
  363. see <<modules-advanced-scripting, advanced scripting documentation>>
  364. [float]
  365. === Document Fields
  366. Most scripting revolve around the use of specific document fields data.
  367. The `doc['field_name']` can be used to access specific field data within
  368. a document (the document in question is usually derived by the context
  369. the script is used). Document fields are very fast to access since they
  370. end up being loaded into memory (all the relevant field values/tokens
  371. are loaded to memory). Note, however, that the `doc[...]` notation only
  372. allows for simple valued fields (can’t return a json object from it)
  373. and makes sense only on non-analyzed or single term based fields.
  374. The following data can be extracted from a field:
  375. [cols="<,<",options="header",]
  376. |=======================================================================
  377. |Expression |Description
  378. |`doc['field_name'].value` |The native value of the field. For example,
  379. if its a short type, it will be short.
  380. |`doc['field_name'].values` |The native array values of the field. For
  381. example, if its a short type, it will be short[]. Remember, a field can
  382. have several values within a single doc. Returns an empty array if the
  383. field has no values.
  384. |`doc['field_name'].empty` |A boolean indicating if the field has no
  385. values within the doc.
  386. |`doc['field_name'].multiValued` |A boolean indicating that the field
  387. has several values within the corpus.
  388. |`doc['field_name'].lat` |The latitude of a geo point type.
  389. |`doc['field_name'].lon` |The longitude of a geo point type.
  390. |`doc['field_name'].lats` |The latitudes of a geo point type.
  391. |`doc['field_name'].lons` |The longitudes of a geo point type.
  392. |`doc['field_name'].distance(lat, lon)` |The `plane` distance (in meters)
  393. of this geo point field from the provided lat/lon.
  394. |`doc['field_name'].distanceWithDefault(lat, lon, default)` |The `plane` distance (in meters)
  395. of this geo point field from the provided lat/lon with a default value.
  396. |`doc['field_name'].distanceInMiles(lat, lon)` |The `plane` distance (in
  397. miles) of this geo point field from the provided lat/lon.
  398. |`doc['field_name'].distanceInMilesWithDefault(lat, lon, default)` |The `plane` distance (in
  399. miles) of this geo point field from the provided lat/lon with a default value.
  400. |`doc['field_name'].distanceInKm(lat, lon)` |The `plane` distance (in
  401. km) of this geo point field from the provided lat/lon.
  402. |`doc['field_name'].distanceInKmWithDefault(lat, lon, default)` |The `plane` distance (in
  403. km) of this geo point field from the provided lat/lon with a default value.
  404. |`doc['field_name'].arcDistance(lat, lon)` |The `arc` distance (in
  405. meters) of this geo point field from the provided lat/lon.
  406. |`doc['field_name'].arcDistanceWithDefault(lat, lon, default)` |The `arc` distance (in
  407. meters) of this geo point field from the provided lat/lon with a default value.
  408. |`doc['field_name'].arcDistanceInMiles(lat, lon)` |The `arc` distance (in
  409. miles) of this geo point field from the provided lat/lon.
  410. |`doc['field_name'].arcDistanceInMilesWithDefault(lat, lon, default)` |The `arc` distance (in
  411. miles) of this geo point field from the provided lat/lon with a default value.
  412. |`doc['field_name'].arcDistanceInKm(lat, lon)` |The `arc` distance (in
  413. km) of this geo point field from the provided lat/lon.
  414. |`doc['field_name'].arcDistanceInKmWithDefault(lat, lon, default)` |The `arc` distance (in
  415. km) of this geo point field from the provided lat/lon with a default value.
  416. |`doc['field_name'].factorDistance(lat, lon)` |The distance factor of this geo point field from the provided lat/lon.
  417. |`doc['field_name'].factorDistance(lat, lon, default)` |The distance factor of this geo point field from the provided lat/lon with a default value.
  418. |`doc['field_name'].geohashDistance(geohash)` |The `arc` distance (in meters)
  419. of this geo point field from the provided geohash.
  420. |`doc['field_name'].geohashDistanceInKm(geohash)` |The `arc` distance (in km)
  421. of this geo point field from the provided geohash.
  422. |`doc['field_name'].geohashDistanceInMiles(geohash)` |The `arc` distance (in
  423. miles) of this geo point field from the provided geohash.
  424. |=======================================================================
  425. [float]
  426. === Stored Fields
  427. Stored fields can also be accessed when executing a script. Note, they
  428. are much slower to access compared with document fields, as they are not
  429. loaded into memory. They can be simply accessed using
  430. `_fields['my_field_name'].value` or `_fields['my_field_name'].values`.
  431. [float]
  432. === Accessing the score of a document within a script
  433. When using scripting for calculating the score of a document (for instance, with
  434. the `function_score` query), you can access the score using the `_score`
  435. variable inside of a Groovy script.
  436. [float]
  437. === Source Field
  438. The source field can also be accessed when executing a script. The
  439. source field is loaded per doc, parsed, and then provided to the script
  440. for evaluation. The `_source` forms the context under which the source
  441. field can be accessed, for example `_source.obj2.obj1.field3`.
  442. Accessing `_source` is much slower compared to using `_doc`
  443. but the data is not loaded into memory. For a single field access `_fields` may be
  444. faster than using `_source` due to the extra overhead of potentially parsing large documents.
  445. However, `_source` may be faster if you access multiple fields or if the source has already been
  446. loaded for other purposes.
  447. [float]
  448. === Groovy Built In Functions
  449. There are several built in functions that can be used within scripts.
  450. They include:
  451. [cols="<,<",options="header",]
  452. |=======================================================================
  453. |Function |Description
  454. |`sin(a)` |Returns the trigonometric sine of an angle.
  455. |`cos(a)` |Returns the trigonometric cosine of an angle.
  456. |`tan(a)` |Returns the trigonometric tangent of an angle.
  457. |`asin(a)` |Returns the arc sine of a value.
  458. |`acos(a)` |Returns the arc cosine of a value.
  459. |`atan(a)` |Returns the arc tangent of a value.
  460. |`toRadians(angdeg)` |Converts an angle measured in degrees to an
  461. approximately equivalent angle measured in radians
  462. |`toDegrees(angrad)` |Converts an angle measured in radians to an
  463. approximately equivalent angle measured in degrees.
  464. |`exp(a)` |Returns Euler's number _e_ raised to the power of value.
  465. |`log(a)` |Returns the natural logarithm (base _e_) of a value.
  466. |`log10(a)` |Returns the base 10 logarithm of a value.
  467. |`sqrt(a)` |Returns the correctly rounded positive square root of a
  468. value.
  469. |`cbrt(a)` |Returns the cube root of a double value.
  470. |`IEEEremainder(f1, f2)` |Computes the remainder operation on two
  471. arguments as prescribed by the IEEE 754 standard.
  472. |`ceil(a)` |Returns the smallest (closest to negative infinity) value
  473. that is greater than or equal to the argument and is equal to a
  474. mathematical integer.
  475. |`floor(a)` |Returns the largest (closest to positive infinity) value
  476. that is less than or equal to the argument and is equal to a
  477. mathematical integer.
  478. |`rint(a)` |Returns the value that is closest in value to the argument
  479. and is equal to a mathematical integer.
  480. |`atan2(y, x)` |Returns the angle _theta_ from the conversion of
  481. rectangular coordinates (_x_, _y_) to polar coordinates (r,_theta_).
  482. |`pow(a, b)` |Returns the value of the first argument raised to the
  483. power of the second argument.
  484. |`round(a)` |Returns the closest _int_ to the argument.
  485. |`random()` |Returns a random _double_ value.
  486. |`abs(a)` |Returns the absolute value of a value.
  487. |`max(a, b)` |Returns the greater of two values.
  488. |`min(a, b)` |Returns the smaller of two values.
  489. |`ulp(d)` |Returns the size of an ulp of the argument.
  490. |`signum(d)` |Returns the signum function of the argument.
  491. |`sinh(x)` |Returns the hyperbolic sine of a value.
  492. |`cosh(x)` |Returns the hyperbolic cosine of a value.
  493. |`tanh(x)` |Returns the hyperbolic tangent of a value.
  494. |`hypot(x, y)` |Returns sqrt(_x2_ + _y2_) without intermediate overflow
  495. or underflow.
  496. |=======================================================================
  497. [float]
  498. === Arithmetic precision in MVEL
  499. When dividing two numbers using MVEL based scripts, the engine tries to
  500. be smart and adheres to the default behaviour of java. This means if you
  501. divide two integers (you might have configured the fields as integer in
  502. the mapping), the result will also be an integer. This means, if a
  503. calculation like `1/num` is happening in your scripts and `num` is an
  504. integer with the value of `8`, the result is `0` even though you were
  505. expecting it to be `0.125`. You may need to enforce precision by
  506. explicitly using a double like `1.0/num` in order to get the expected
  507. result.