repeat

Copies input data a specified number of times and outputs it.

Command properties

ItemDescription
Command typeProcessing query
Required permissionNone
License usageN/A
Parallel executionSupported
Distributed executionNot supported

Syntax

repeat count=INT [_repidx={t|f}]

Options

count=INT
Number of times to repeat each input record.
_repidx={t|f}
Whether to output the repeat index field (default: f)
  • t: Adds a _repidx field to each copy with a zero-based index value.
  • f: Does not add a repeat index field.

Output fields

FieldTypeDescription
_repidxintegerRepeat index (zero-based). Output only when the _repidx=t option is specified.

Error codes

Parse errors
Error codeMessageDescription
missing-count-option-The count option is not specified
Runtime errors

N/A

Description

The repeat command copies each input record the number of times specified by count and outputs the copies. For example, specifying count=3 outputs 3 identical records for each input record.

With the _repidx=t option, a zero-based repeat index field (_repidx) is added to each copy, allowing you to distinguish which copy it is.

Examples

  1. Repeating records 3 times

    json "[{'name': 'Alice'}, {'name': 'Bob'}]"
    | repeat count=3
    

    Each record is copied 3 times, outputting a total of 6 records.

  2. Outputting with the repeat index

    json "[{'name': 'Alice'}]"
    | repeat count=3 _repidx=t
    

    Outputs 3 records with _repidx values of 0, 1, and 2.

  3. Generating consecutive dates using the repeat index

    json "[{'base_date': '2025-01-01'}]"
    | repeat count=7 _repidx=t
    | eval date = dateadd(date(base_date, "yyyy-MM-dd"), "day", _repidx)
    | fields date
    

    Generates 7 consecutive dates starting from the base date.