Splunk® Data Stream Processor

Function Reference

Acrobat logo Download manual as PDF

On October 30, 2022, all 1.2.x versions of the Splunk Data Stream Processor will reach its end of support date. See the Splunk Software Support Policy for details. For information about upgrading to a supported version, see the Upgrade the Splunk Data Stream Processor topic.
Acrobat logo Download topic as PDF

Batch Bytes

This topic describes how to use the function in the .


The Batch Bytes function batches incoming byte arrays by size, count, or milliseconds and outputs a single byte array concatenated by a user defined separator.

There are two functions for batching records: Batch Bytes and Batch Records. Use Batch Bytes when you need to serialize your data before batching. Use Batch Records when you want to do serialization (if any) after batching. Batch Bytes concatenates the batched byte array payloads delimited by an optional user-defined separator. This means that Batch Bytes is best used for row-based style batched payloads, such as CSV or JSON streaming (concatenated JSON records), but it will not be useful for bulk or columnar formats.

Function Input/Output Schema

Function Input
This function takes in byte arrays to be batched.
Function Output
This function outputs a byte array that is a concatenation of all byte[] payloads.


The required syntax is in bold.

bytes: <byte array>
separator: <string>
size: <string> B | KB | MB
num_events: <long>
millis: <long>

Required arguments

Syntax: byte[]
Description: The byte array payload to be batched.

Optional arguments

Syntax: <string>
Description: A delimiter that separates the byte payloads.
Example: \\n
Syntax: <string> B | KB | MB
Description: The maximum size, in bytes, of the emitted batched byte[]. The size of your emitted batched bytes cannot exceed 100 MB.
Default: 10MB
Example: 1024B
Syntax: <long>
Description: The maximum number of payloads per batch.
Default: 100,000,000
Example: 2000
Syntax: <long>
Description: The interval, in milliseconds, at which to send batched records. Cannot exceed 8000 milliseconds (8 seconds).
Default: 2000 milliseconds (2 seconds).
Example: 2000


The following is an example of batched data. Assume that your data looks something like the following snippet, and you've configured your function with the arguments shown in the SPL2 example.

{"event": "my data 1", "index": "syslog", "sourcetype": "syslog"}
{"event": "my data 2", "index": "secindex", "sourcetype": "security"}
{"event": "my data 3", "index": "proxy", "sourcetype": "squid"}

When the batch trigger fires, Batch Bytes outputs a single record with a byte array.

Record {
   "bytes": byte[]

The outputted byte array is the following string as UTF-8 bytes.

{"event": "my data 1", "index": "syslog", "sourcetype": "syslog"}{"event": "my data 2", "index": "secindex", "sourcetype": "security"}{"event": "my data 3", "index": "proxy", "sourcetype": "squid"}


An example of a common use case follows. These examples assume that you have added the function to your pipeline.

SPL2 Example: Batch Splunk JSON events and send the payload once it reaches 5MB or 2 minutes have passed

This example assumes that you are in the SPL View.

Suppose you have Splunk JSON events outputted by the to_splunk_json function. To batch bytes of those Splunk JSON events and only send payloads once they reach 5MB or 2 minutes have passed:

... | to_splunk_json index=cast(map_get(attributes, "index"), "string")  | batch_bytes bytes=to_bytes(json) size="5MB" millis="120000" |...;
Last modified on 27 October, 2021
Apply Timestamp Extraction
Batch Records

This documentation applies to the following versions of Splunk® Data Stream Processor: 1.2.1, 1.2.2-patch02, 1.2.4, 1.2.5, 1.3.0, 1.3.1, 1.4.0, 1.4.1, 1.4.2

Was this documentation topic helpful?

You must be logged into splunk.com in order to post comments. Log in now.

Please try to keep this discussion focused on the content covered in this documentation topic. If you have a more general question about Splunk functionality or are experiencing a difficulty with Splunk, consider posting a question to Splunkbase Answers.

0 out of 1000 Characters