-
Notifications
You must be signed in to change notification settings - Fork 507
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
Add JSON processor documentation #5982
Merged
Changes from 13 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
8870501
Add JSON processor documentation
vagimeli adcbdcb
Merge branch 'main' into geo-json
vagimeli 0d189f6
Add pipeline examples
vagimeli 50d6924
Merge branch 'main' into geo-json
vagimeli bb5c62f
Add parameters
vagimeli bd34306
Merge branch 'main' into geo-json
vagimeli 3fc0a4b
Update parameters
vagimeli 0ad2283
Merge branch 'main' into geo-json
vagimeli de81228
Merge branch 'main' into geo-json
vagimeli 6bbcb67
Update json.md
vagimeli bbbd4bb
Update json.md
vagimeli ceb2732
Address tech review feedback
vagimeli 916429a
Merge branch 'main' into geo-json
vagimeli 058fb48
Update _ingest-pipelines/processors/json.md
vagimeli f735d4e
Update _ingest-pipelines/processors/json.md
vagimeli 61ba96e
Update _ingest-pipelines/processors/json.md
vagimeli 608dfe9
Update _ingest-pipelines/processors/json.md
vagimeli ffc3b69
Update _ingest-pipelines/processors/json.md
vagimeli 36ee8cc
Update _ingest-pipelines/processors/json.md
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 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,199 @@ | ||
--- | ||
layout: default | ||
title: JSON | ||
parent: Ingest processors | ||
nav_order: 170 | ||
--- | ||
|
||
# JSON processor | ||
|
||
The `json` processor serializes a string-valued field into a map of maps, which can be useful for various data processing and enrichment tasks. | ||
vagimeli marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
The following is the syntax for the `json` processor: | ||
|
||
```json | ||
{ | ||
"processor": { | ||
"json": { | ||
"field": "<field_name>", | ||
"target_field": "<target_field_name>", | ||
"add_to_root": <boolean> | ||
} | ||
} | ||
} | ||
``` | ||
{% include copy-curl.html %} | ||
|
||
## Configuration parameters | ||
|
||
The following table lists the required and optional parameters for the `json` processor. | ||
|
||
Parameter | Required/Optional | Description | | ||
|-----------|-----------|-----------| | ||
`field` | Required | The name of the field containing the JSON-formatted string to be deserialized. | ||
`target_field` | Optional | The name of the field where the deserialized JSON data will be stored. If `target_field` is unspecified, the value is stored in field. If `target_field` exists, it is overwritten. | ||
vagimeli marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The last two sentences here have me a bit confused. Can we check for clarity/accuracy? |
||
`add_to_root` | Optional | A boolean flag that determines whether the deserialized JSON data should be added to the root of the document (`true`) or stored in the target_field (`false`). If `add_to_root` is `true`, then `target-field` is invalid. Default value is `false`. | ||
Check failure on line 35 in _ingest-pipelines/processors/json.md GitHub Actions / vale[vale] _ingest-pipelines/processors/json.md#L35
Raw output
|
||
vagimeli marked this conversation as resolved.
Show resolved
Hide resolved
|
||
`description` | Optional | A description of the processor's purpose or configuration. | ||
`if` | Optional | Specifies to conditionally execute the processor. | ||
`ignore_failure` | Optional | Specifies to ignore failures for the processor. See [Handling pipeline failures]({{site.url}}{{site.baseurl}}/ingest-pipelines/pipeline-failures/). | ||
vagimeli marked this conversation as resolved.
Show resolved
Hide resolved
|
||
`on_failure`| Optional | Specifies a list of processors to run if the processor fails during execution. These processors are executed in the order they are specified. | ||
`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 | ||
|
||
The following query creates a pipeline named `my-json-pipeline` that uses the `json` processor to process JSON data and enrich the documents with additional information: | ||
|
||
```json | ||
PUT _ingest/pipeline/my-json-pipeline | ||
{ | ||
"description": "Example pipeline using the JsonProcessor", | ||
"processors": [ | ||
{ | ||
"json": { | ||
"field": "raw_data", | ||
"target_field": "parsed_data" | ||
"on_failure": [ | ||
{ | ||
"set": { | ||
"field": "error_message", | ||
"value": "Failed to parse JSON data" | ||
} | ||
}, | ||
{ | ||
"fail": { | ||
"message": "Failed to process JSON data" | ||
} | ||
} | ||
] | ||
} | ||
}, | ||
{ | ||
"set": { | ||
"field": "processed_timestamp", | ||
"value": "{{_ingest.timestamp}}" | ||
} | ||
} | ||
] | ||
} | ||
``` | ||
{% 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/my-json-pipeline/_simulate | ||
{ | ||
"docs": [ | ||
{ | ||
"_source": { | ||
"raw_data": "{\"name\":\"John\",\"age\":30,\"city\":\"New York\"}" | ||
} | ||
}, | ||
{ | ||
"_source": { | ||
"raw_data": "{\"name\":\"Jane\",\"age\":25,\"city\":\"Los Angeles\"}" | ||
} | ||
} | ||
] | ||
} | ||
``` | ||
{% include copy-curl.html %} | ||
|
||
#### Response | ||
|
||
The following example response confirms that the pipeline is working as expected: | ||
|
||
```json | ||
{ | ||
"docs": [ | ||
{ | ||
"doc": { | ||
"_index": "_index", | ||
"_id": "_id", | ||
"_source": { | ||
"processed_timestamp": "2024-05-30T15:24:48.064472090Z", | ||
"raw_data": """{"name":"John","age":30,"city":"New York"}""", | ||
"parsed_data": { | ||
"name": "John", | ||
"city": "New York", | ||
"age": 30 | ||
} | ||
}, | ||
"_ingest": { | ||
"timestamp": "2024-05-30T15:24:48.06447209Z" | ||
} | ||
} | ||
}, | ||
{ | ||
"doc": { | ||
"_index": "_index", | ||
"_id": "_id", | ||
"_source": { | ||
"processed_timestamp": "2024-05-30T15:24:48.064543006Z", | ||
"raw_data": """{"name":"Jane","age":25,"city":"Los Angeles"}""", | ||
"parsed_data": { | ||
"name": "Jane", | ||
"city": "Los Angeles", | ||
"age": 25 | ||
} | ||
}, | ||
"_ingest": { | ||
"timestamp": "2024-05-30T15:24:48.064543006Z" | ||
} | ||
} | ||
} | ||
] | ||
} | ||
``` | ||
{% include copy-curl.html %} | ||
|
||
### Step 3: Ingest a document | ||
|
||
The following query ingests a document into an index named `my-index`: | ||
|
||
```json | ||
POST my-index/_doc?pipeline=my-json-pipeline | ||
{ | ||
"raw_data": "{\"name\":\"John\",\"age\":30,\"city\":\"New York\"}" | ||
} | ||
``` | ||
{% include copy-curl.html %} | ||
|
||
#### Response | ||
|
||
This response confirms that the document with the JSON data from the `raw_data` field was successfully indexed: | ||
vagimeli marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
```json | ||
{ | ||
"_index": "my-index", | ||
"_id": "mo8yyo8BwFahnwl9WpxG", | ||
"_version": 1, | ||
"result": "created", | ||
"_shards": { | ||
"total": 2, | ||
"successful": 1, | ||
"failed": 0 | ||
}, | ||
"_seq_no": 3, | ||
"_primary_term": 2 | ||
} | ||
``` | ||
{% include copy-curl.html %} | ||
|
||
### Step 4 (Optional): Retrieve the document | ||
|
||
To retrieve the document, run the following query: | ||
|
||
```json | ||
GET my-index/_doc/1 | ||
``` | ||
{% include copy-curl.html %} |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is "string-valued" the right phrasing here, or should it just be "string value field"?