to_integer.asciidoc 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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,esql]
  8. ----
  9. include::{esql-specs}/ints.csv-spec[tag=to_int-long]
  10. ----
  11. returns:
  12. [%header,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