to_integer.asciidoc 1.2 KB

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