generated from amazon-archives/__template_Apache-2.0
-
Couldn't load subscription status.
- Fork 621
Add foreach processor documentation #5981
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
3ead1ed
Add foreach processor documentation
vagimeli c06ff43
Merge branch 'main' into foreach-processor
vagimeli c10ed94
Add pipeline example requests and responses
vagimeli fed57d8
Merge branch 'main' into foreach-processor
vagimeli 8237aef
Merge branch 'main' into foreach-processor
vagimeli 55fe58f
Add pipeline examples
vagimeli eafa2b8
Address tech review comments
vagimeli b8ad27b
Merge branch 'main' into foreach-processor
vagimeli dda29a0
Update _ingest-pipelines/processors/foreach.md
vagimeli a55b31a
Update _ingest-pipelines/processors/foreach.md
vagimeli d4bc18f
Address editorial review comments
vagimeli c596869
Merge branch 'main' into foreach-processor
vagimeli File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,209 @@ | ||
| --- | ||
| layout: default | ||
| title: `foreach` | ||
| parent: Ingest processors | ||
| nav_order: 110 | ||
| --- | ||
|
|
||
| # `foreach` processor | ||
|
|
||
| The `foreach` processor is used to iterate over a list of values in an input document and apply a transformation to each value. This can be useful for tasks like processing all the elements in an array consistently, such as converting all elements in a string to lowercase or uppercase. | ||
|
|
||
| The following is the syntax for the `foreach` processor: | ||
|
|
||
| ```json | ||
| { | ||
| "foreach": { | ||
| "field": "<field_name>", | ||
| "processor": { | ||
| "<processor_type>": { | ||
| "<processor_config>": "<processor_value>" | ||
| } | ||
| } | ||
| } | ||
| } | ||
| ``` | ||
| {% include copy-curl.html %} | ||
|
|
||
| ## Configuration parameters | ||
|
|
||
| The following table lists the required and optional parameters for the `foreach` processor. | ||
|
|
||
| Parameter | Required/Optional | Description | | ||
| |-----------|-----------|-----------| | ||
| `field` | Required | The array field to iterate over. | ||
| `processor` | Required | The processor to execute against each field. | ||
| `ignore_missing` | Optional | If `true` and the specified field does not exist or is null, then the processor will quietly exit without modifying the document. | ||
| `description` | Optional | A brief description of the processor. | ||
| `if` | Optional | A condition for running the processor. | ||
| `ignore_failure` | Optional | Specifies whether the processor continues execution even if it encounters an error. If set to `true`, then failures are ignored. Default is `false`. | ||
| `on_failure` | Optional | A list of processors to run if the processor fails. | ||
| `tag` | Optional | An identifier tag for the processor. Useful for debugging in order to distinguish between processors of the same type. | ||
|
|
||
| ## Using the processor | ||
|
|
||
| Follow these steps to use the processor in a pipeline. | ||
|
|
||
| ### Step 1: Create a pipeline | ||
vagimeli marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| The following query creates a pipeline named `test-foreach` that uses the `foreach` processor to iterate over each element in the `protocols` field: | ||
|
|
||
| ```json | ||
| PUT _ingest/pipeline/test-foreach | ||
| { | ||
| "description": "Lowercase all the elements in an array", | ||
| "processors": [ | ||
| { | ||
| "foreach": { | ||
| "field": "protocols", | ||
| "processor": { | ||
| "lowercase": { | ||
| "field": "_ingest._value" | ||
| } | ||
| } | ||
| } | ||
| ``` | ||
| {% include copy-curl.html %} | ||
|
|
||
| ### Step 2 (Optional): Test the pipeline | ||
|
|
||
| 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/test-foreach/_simulate | ||
| { | ||
| "docs": [ | ||
| { | ||
| "_index": "testindex1", | ||
| "_id": "1", | ||
| "_source": { | ||
| "protocols": ["HTTP","HTTPS","TCP","UDP"] | ||
| } | ||
| } | ||
| ] | ||
| } | ||
| ``` | ||
| {% include copy-curl.html %} | ||
|
|
||
| #### Response | ||
|
|
||
| The following example response confirms that the pipeline is working as expected, showing that the four elements have been lowercased: | ||
|
|
||
| ```json | ||
| { | ||
| "docs": [ | ||
| { | ||
| "doc": { | ||
| "_index": "testindex1", | ||
| "_id": "1", | ||
| "_source": { | ||
| "protocols": [ | ||
| "http", | ||
| "https", | ||
| "tcp", | ||
| "udp" | ||
| ] | ||
| }, | ||
| "_ingest": { | ||
| "_value": null, | ||
| "timestamp": "2024-05-23T02:44:10.8201Z" | ||
| } | ||
| } | ||
| } | ||
| ] | ||
| } | ||
|
|
||
| ``` | ||
| {% include copy-curl.html %} | ||
|
|
||
| ### Step 3: Ingest a document | ||
|
|
||
| The following query ingests a document into an index named `testindex1`: | ||
|
|
||
| ```json | ||
| POST testindex1/_doc/1?pipeline=test-foreach | ||
| { | ||
| "protocols": ["HTTP","HTTPS","TCP","UDP"] | ||
| } | ||
| ``` | ||
| {% include copy-curl.html %} | ||
|
|
||
| #### Response | ||
|
|
||
| The request indexes the document into the index `testindex1` and applies the pipeline before indexing: | ||
|
|
||
| ```json | ||
| { | ||
| "_index": "testindex1", | ||
| "_id": "1", | ||
| "_version": 6, | ||
| "result": "created", | ||
| "_shards": { | ||
| "total": 2, | ||
| "successful": 1, | ||
| "failed": 0 | ||
| }, | ||
| "_seq_no": 5, | ||
| "_primary_term": 67 | ||
| } | ||
| ``` | ||
| {% include copy-curl.html %} | ||
|
|
||
| ### Step 4 (Optional): Retrieve the document | ||
|
|
||
| To retrieve the document, run the following query: | ||
|
|
||
| ```json | ||
| GET testindex1/_doc/1 | ||
| ``` | ||
| {% include copy-curl.html %} | ||
|
|
||
| #### Response | ||
|
|
||
| The response shows the document with the extracted JSON data from the `users` field: | ||
|
|
||
| ```json | ||
| { | ||
| "_index": "testindex1", | ||
| "_id": "1", | ||
| "_version": 6, | ||
| "_seq_no": 5, | ||
| "_primary_term": 67, | ||
| "found": true, | ||
| "_source": { | ||
| "protocols": [ | ||
| "http", | ||
| "https", | ||
| "tcp", | ||
| "udp" | ||
| ] | ||
| } | ||
| } | ||
|
|
||
| { | ||
| "docs": [ | ||
| { | ||
| "doc": { | ||
| "_index": "testindex1", | ||
| "_id": "1", | ||
| "_source": { | ||
| "protocols": [ | ||
| "http", | ||
| "https", | ||
| "tcp", | ||
| "udp" | ||
| ] | ||
| }, | ||
| "_ingest": { | ||
| "_value": null, | ||
| "timestamp": "2024-05-23T02:44:10.8201Z" | ||
| } | ||
| } | ||
| } | ||
| ] | ||
| } | ||
| ``` | ||
| {% include copy-curl.html %} | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.