2023-08-29 16:07:34 -04:00
---
layout: default
title: Append
2023-10-17 17:22:28 -04:00
parent: Ingest processors
2023-08-29 16:07:34 -04:00
nav_order: 10
2023-10-17 17:22:28 -04:00
redirect_from:
- /api-reference/ingest-apis/processors/append/
2023-08-29 16:07:34 -04:00
---
2023-10-17 17:22:28 -04:00
2023-12-05 14:49:46 -05:00
# Append processor
2023-08-29 16:07:34 -04:00
The `append` processor is used to add values to a field:
- If the field is an array, the `append` processor appends the specified values to that array.
- If the field is a scalar field, the `append` processor converts it to an array and appends the specified values to that array.
- If the field does not exist, the `append` processor creates an array with the specified values.
2023-12-12 15:16:16 -05:00
### Syntax
2023-08-29 16:07:34 -04:00
The following is the syntax for the `append` processor:
```json
{
2023-08-31 19:26:10 -04:00
"append": {
"field": "your_target_field",
"value": ["your_appended_value"]
}
2023-08-29 16:07:34 -04:00
}
```
{% include copy-curl.html %}
## Configuration parameters
The following table lists the required and optional parameters for the `append` processor.
2023-12-12 15:16:16 -05:00
Parameter | Required/Optional | Description |
2023-08-29 16:07:34 -04:00
|-----------|-----------|-----------|
2023-12-12 15:16:16 -05:00
`field` | Required | The name of the field containing the data to be appended. Supports [template snippets ]({{site.url}}{{site.baseurl}}/ingest-pipelines/create-ingest/#template-snippets ).|
`value` | Required | The value to be appended. This can be a static value or a dynamic value derived from existing fields. Supports [template snippets ]({{site.url}}{{site.baseurl}}/ingest-pipelines/create-ingest/#template-snippets ). |
2023-08-29 16:07:34 -04:00
`description` | Optional | A brief description of the processor. |
2023-12-12 15:16:16 -05:00
`if` | Optional | A condition for running the processor. |
`ignore_failure` | Optional | Specifies whether the processor continues execution even if it encounters errors. If set to `true` , failures are ignored. Default is `false` . |
2023-08-29 16:07:34 -04:00
`on_failure` | Optional | A list of processors to run if the processor fails. |
2023-12-12 15:16:16 -05:00
`tag` | Optional | An identifier tag for the processor. Useful for debugging in order to distinguish between processors of the same type. |
2023-08-29 16:07:34 -04:00
## Using the processor
Follow these steps to use the processor in a pipeline.
2023-12-12 15:16:16 -05:00
**Step 1: Create a pipeline**
2023-08-29 16:07:34 -04:00
The following query creates a pipeline, named `user-behavior` , that has one append processor. It appends the `page_view` of each new document ingested into OpenSearch to an array field named `event_types` :
```json
PUT _ingest/pipeline/user-behavior
{
"description": "Pipeline that appends event type",
"processors": [
{
"append": {
"field": "event_types",
"value": ["page_view"]
}
}
]
}
```
{% include copy-curl.html %}
2023-12-12 15:16:16 -05:00
**Step 2 (Optional): Test the pipeline**
2023-08-29 16:07:34 -04:00
It is recommended that you test your pipeline before you ingest documents.
{: .tip}
To test the pipeline, run the following query:
```json
POST _ingest/pipeline/user-behavior/_simulate
{
2023-08-31 19:26:10 -04:00
"docs":[
{
"_source":{
}
}
]
2023-08-29 16:07:34 -04:00
}
```
{% include copy-curl.html %}
2023-12-12 15:16:16 -05:00
**Response**
2023-08-29 16:07:34 -04:00
The following response confirms that the pipeline is working as expected:
```json
{
"docs": [
{
"doc": {
"_index": "_index",
"_id": "_id",
"_source": {
"event_types": [
"page_view"
]
},
"_ingest": {
"timestamp": "2023-08-28T16:55:10.621805166Z"
}
}
}
]
}
```
2023-12-12 15:16:16 -05:00
**Step 3: Ingest a document**
2023-08-29 16:07:34 -04:00
The following query ingests a document into an index named `testindex1` :
```json
PUT testindex1/_doc/1?pipeline=user-behavior
{
}
```
{% include copy-curl.html %}
2023-12-12 15:16:16 -05:00
**Step 4 (Optional): Retrieve the document**
2023-08-29 16:07:34 -04:00
To retrieve the document, run the following query:
```json
GET testindex1/_doc/1
```
{% include copy-curl.html %}
Because the document does not contain an `event_types` field, an array field is created and the event is appended to the array:
```json
{
"_index": "testindex1",
"_id": "1",
"_version": 2,
"_seq_no": 1,
"_primary_term": 1,
"found": true,
"_source": {
"event_types": [
"page_view"
]
}
}
```