Int
less than a minute
Overview
Converts a given value to an integer type (int64). Use Int when you need whole numbers (e.g., status codes, counts). Use Double when dealing with measurements that may require precision or when the input might be a floating point number (e.g., time durations, temperatures).
Syntax
Int(value)
- value: the bracket notation location of the field to convert.
Value types:
- float64: The fractional part is discarded (truncation towards zero).
- string: Attempts to parse an integer from the string; returns nil if the parsing fails.
- bool: Returns 1 if true, 0 if false.
- int64: Returns the value without changes.
Examples
Input
{
"_type": "log",
"attributes": {
"http_code": "307"
},
"body": "{\"host\": \"10.37.232.225\", \"user-identifier\": \"07af2ad8-a96c-4664-92a5-eb5629c41b6e\", \"time_local\": \"2024-12-11T03:26:53.801093Z\", \"method\": \"GET\", \"request\": \"/styles/main.css\", \"protocol\": \"HTTP/2\", \"status\": 307, \"bytes_sent\": 1151}",
"resource": {...}
}
Statement
set(attributes["http_code_int"], Int(attributes["http_code"]))
Output
{
"_type": "log",
"attributes": {
"http_code": "307",
"http_code_int": 307
},
"body": "{\"host\": \"10.37.232.225\", \"user-identifier\": \"07af2ad8-a96c-4664-92a5-eb5629c41b6e\", \"time_local\": \"2024-12-11T03:26:53.801093Z\", \"method\": \"GET\", \"request\": \"/styles/main.css\", \"protocol\": \"HTTP/2\", \"status\": 307, \"bytes_sent\": 1151}",
"resource": {...},
"timestamp": 1733892615586
}
The http_code string was converted to an integer 307 and saved as http_code_int.