Navigation

expr

On this page

Definition

expr

Evaluates an expression against each input document and outputs the evaluated documents. The $concat and the $match operators are available for use in the expression.

The expr action stage has the following syntax:

Tip

In the stages, the action arguments can make use of variables (%%vars) defined for the stage as well as defined constants and expansions.

{ "service": "", "action": "expr", "args": {"expression": <document> } }

The expr action takes the following arguments:

Argument Type Description
expression document An expression to evaluate. $concat and the $match operators are available for use in the expression.

Examples

Consider the following pipeline:

[
   {"service":"","action":"literal","args":{"items":[{"adjective":"brown","noun":"cow"},{"adjective":"red","noun":"hen"}]}},
   {"service":"","action":"expr","args":{"expression":{"y":{"%concat":["%%vars.adj"," ","%%vars.noun"]}}},"let":{"adj":"%%item.adjective","noun":"%%item.noun"}}
]

Stage1: The literal stage outputs the following documents:

{"adjective":"brown","noun":"cow"}
{"adjective":"red","noun":"hen"}

Stage2: For each input document, the expr stage

  • binds the input document field adjective to a variable adj and the input document field noun to the variable noun as indicated by:

    "let":{"adj":"%%item.adjective","noun":"%%item.noun"}

  • then, evaluates the expression:

    {"y":{"%concat":["%%vars.adj"," ","%%vars.noun"]}}

  • to output the following documents:

{ "y": "brown cow" },
{ "y": "red hen" }
←   encode literal  →