{{ action }} Scripted Field

By default, Elasticsearch scripts use Lucene Expressions , which is a lot like JavaScript, but limited to basic arithmetic, bitwise and comparison operations. We'll let you do some reading on Lucene Expressions To access values in the document use the following format:

doc['some_field'].value

There are a few limitations when using Lucene Expressions:

  • Only numeric fields may be accessed
  • Stored fields are not available
  • If a field is sparse (only some documents contain a value), documents missing the field will have a value of 0

Here are all the operations available to scripted fields:

  • Arithmetic operators: + - * / %
  • Bitwise operators: | & ^ ~ << >> >>>
  • Boolean operators (including the ternary operator): && || ! ?:
  • Comparison operators: < <= == >= >
  • Common mathematic functions: abs ceil exp floor ln log10 logn max min sqrt pow
  • Trigonometric library functions: acosh acos asinh asin atanh atan atan2 cosh cos sinh sin tanh tan
  • Distance functions: haversin
  • Miscellaneous functions: min, max

Proceed with caution

Scripted fields can be used to display and aggregate calculated values. As such, they can be very slow, and if done incorrectly, can cause Kibana to be unusable. There's no safety net here. If you make a typo, unexpected exceptions will be thrown all over the place!

You already have a field with the name {{ scriptedField.name }}. Naming your scripted field with the same name means you won't be able to query both fields at the same time.