> ## Documentation Index
> Fetch the complete documentation index at: https://doc.lucidworks.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Template Expressions

[localhost link]: http://localhost:3000/docs/5/fusion/getting-data-out/query-enhancement/template-expressions/overview

[mintlify link]: https://doc.lucidworks.com/docs/5/fusion/getting-data-out/query-enhancement/template-expressions/overview.md

[old doc.lw link]: https://doc.lucidworks.com/fusion/5.9/10911.md

Template expressions are a way to map field values in a document. They are used to configure some Fusion index pipeline stages, query pipeline stages, and messaging services. When the value of a configuration parameter is a template expression, that expression is dynamically evaluated at runtime by the [StringTemplate](https://github.com/antlr/stringtemplate4/blob/master/doc/cheatsheet.md) library.

Fusion template expressions are delimited by angle bracket characters `<` and `>`.
The expression consists of the name of a variable in the scope of that component.

Since these variables are Java objects, if object **foo** of type Foo has a field named **bar**, the expression **`<foo.bar>`** will evaluate to the string representation of the contents of field **bar**.

For example, given a PipelineDocument where a field named **title** has a value of **Star Wars**, the template expression `<doc.title>` evaluates to **Star Wars**.

> [card] Key questions to get you started
>
> Powered by Lucidworks Agent Studio

## Index pipeline stage template expression variables

Index stages have the following variables available:

* `ctx`. [Context](https://javadoc.lucidworks.com/fusion-pipeline-javadocs/5.9/com/lucidworks/apollo/pipeline/Context.html): used to pass variables between stages
* `doc`. [PipelineDocument](https://javadoc.lucidworks.com/fusion-pipeline-javadocs/5.9/com/lucidworks/apollo/common/pipeline/PipelineDocument.html): Fusion internal representation of a Solr Document. Please note that if you change this class in ways that affect the serialized form (adding fields, for example) you need to change the deserialization code in `GenericJSONDocumentMessageReader`.
* `_NOW_`. The current time in Solr date format (UTC), such as `2025-01-15T09:30:00.000Z`.

For example, `<doc.title>` returns all values of the `title` field, concatenated with no separator.
To return only the first value of a multi-valued field, use `<first(doc.title)>`.

## Query pipeline stage template expression variables

Query stages have the following variables available:

* `ctx`. [Context](https://javadoc.lucidworks.com/fusion-pipeline-javadocs/5.9/com/lucidworks/apollo/pipeline/Context.html): used to pass variables between stages
* `request`. The query request. Use `<request.paramName>` to return the values of a request parameter.
* `response`. The query response, if one exists.
* `_NOW_`. The current time in Solr date format (UTC), such as `2025-01-15T09:30:00.000Z`.

For example, `<request.q>` returns all values of the `q` request parameter, concatenated with no separator.
To return only the first value of a multi-valued parameter, use `<first(request.paramName)>`.

## Example

Check that a query has an `fq` filter on a given field for a given value:

In the UI, set property name to `ids` and Property Value to `req.hasParam("fq")`

![javascript values](https://mintcdn.com/lucidworks/1R8QVvJzt46cZDT6/assets/images/4.2/javascript-field.png?fit=max\&auto=format\&n=1R8QVvJzt46cZDT6\&q=85\&s=0d4b01cb50c6bc49a93214990dbcd1b8)

## Messaging services template expression variables

Messages have a set of variables which correspond to the parts of a system message:

* id
* to
* from
* subject
* body
* type
* schedule

A system message is the result of evaluating the following expression:

```xml wrap  theme={"dark"}
<id><to><from><subject><body><type><schedule>
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.