to_integer.asciidoc 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. [discrete]
  2. [[esql-to_integer]]
  3. === `TO_INTEGER`
  4. Converts an input value to an integer value.
  5. The input can be a single- or multi-valued field or an expression. The input
  6. type must be of a boolean, date, string or numeric type.
  7. Example:
  8. [source.merge.styled,esql]
  9. ----
  10. include::{esql-specs}/ints.csv-spec[tag=to_int-long]
  11. ----
  12. [%header.monospaced.styled,format=dsv,separator=|]
  13. |===
  14. include::{esql-specs}/ints.csv-spec[tag=to_int-long-result]
  15. |===
  16. Note that in this example, the last value of the multi-valued field cannot
  17. be converted as an integer. When this happens, the result is a *null* value.
  18. In this case a _Warning_ header is added to the response. The header will
  19. provide information on the source of the failure:
  20. `"Line 1:61: evaluation of [TO_INTEGER(long)] failed, treating result as null. Only first 20 failures recorded."`
  21. A following header will contain the failure reason and the offending value:
  22. `"org.elasticsearch.xpack.ql.QlIllegalArgumentException: [501379200000] out of [integer] range"`
  23. If the input parameter is of a date type, its value will be interpreted as
  24. milliseconds since the https://en.wikipedia.org/wiki/Unix_time[Unix epoch],
  25. converted to integer.
  26. Boolean *true* will be converted to integer *1*, *false* to *0*.
  27. Alias: TO_INT