Skip to content

Commit

Permalink
Merge branch 'main' into html-strip
Browse files Browse the repository at this point in the history
  • Loading branch information
vagimeli authored Jun 6, 2024
2 parents 8fd346d + 9985ba3 commit ad46155
Show file tree
Hide file tree
Showing 4 changed files with 327 additions and 2 deletions.
2 changes: 1 addition & 1 deletion _benchmark/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ To perform the Quickstart steps, you'll need to fulfill the following prerequisi

## Set up an OpenSearch cluster

If you don't already have an active OpenSearch cluster, you can launch a new OpenSearch cluster to use with OpenSerch Benchmark.
If you don't already have an active OpenSearch cluster, you can launch a new OpenSearch cluster to use with OpenSearch Benchmark.

- Using **Docker Compose**. For instructions on how to use Docker Compose, see [OpenSearch Quickstart]({{site.url}}{{site.baseurl}}/quickstart/).
- Using **Tar**. For instructions on how to install OpenSearch with Tar, see [Installing OpenSearch > Tarball]({{site.url}}{{site.baseurl}}/install-and-configure/install-opensearch/tar#step-1-download-and-unpack-opensearch).
Expand Down
170 changes: 170 additions & 0 deletions _ingest-pipelines/processors/gsub.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
---
layout: default
title: gsub
parent: Ingest processors
nav_order: 130
---

# Gsub processor

The `gsub` processor performs a regular expression search-and-replace operation on string fields in incoming documents. If the field contains an array of strings, the operation is applied to all elements in the array. However, if the field contains non-string values, the processor throws an exception. Use cases for the `gsub` processor include removing sensitive information from log messages or user-generated content, normalizing data formats or conventions (for example, converting date formats, removing special characters), and extracting or transforming substrings from field values for further processing or analysis.

The following is the syntax for the `gsub` processor:

```json
"gsub": {
"field": "field_name",
"pattern": "regex_pattern",
"replacement": "replacement_string"
}
```
{% include copy-curl.html %}

## Configuration parameters

The following table lists the required and optional parameters for the `gsub` processor.

Parameter | Required/Optional | Description |
|-----------|-----------|-----------|
`field` | Required | The field to apply the replacement to.
`pattern` | Required | The pattern to be replaced.
`replacement` | Required | The string that will replace the matching patterns.
`target_field` | Optional | The name of the field in which to store the parsed data. If `target_field` is not specified, the parsed data replaces the original data in the `field` field. Default is `field`.
`if` | Optional | A condition for running the processor.
`ignore_missing` | Optional | Specifies whether the processor should ignore documents that do not contain the specified field. Default is `false`.
`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

The following query creates a pipeline named `gsub_pipeline` that uses the `gsub` processor to replace all occurrences of the word `error` with the word `warning` in the `message` field:

```json
PUT _ingest/pipeline/gsub_pipeline
{
"description": "Replaces 'error' with 'warning' in the 'message' field",
"processors": [
{
"gsub": {
"field": "message",
"pattern": "error",
"replacement": "warning"
}
}
]
}
```
{% 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/gsub_pipeline/_simulate
{
"docs": [
{
"_source": {
"message": "This is an error message"
}
}
]
}
```
{% include copy-curl.html %}

#### Response

The following response confirms that the pipeline is working as expected:

```json
{
"docs": [
{
"doc": {
"_index": "_index",
"_id": "_id",
"_source": {
"message": "This is an warning message"
},
"_ingest": {
"timestamp": "2024-05-22T19:47:00.645687211Z"
}
}
}
]
}
```
{% include copy-curl.html %}

### Step 3: Ingest a document

The following query ingests a document into an index named `logs`:

```json
PUT logs/_doc/1?pipeline=gsub_pipeline
{
"message": "This is an error message"
}
```
{% include copy-curl.html %}

#### Response

The following response shows that the request indexed the document into the index named `logs` and that the `gsub` processor replaced all occurrences of the word `error` with the word `warning` in the `message` field:

```json
{
"_index": "logs",
"_id": "1",
"_version": 1,
"result": "created",
"_shards": {
"total": 2,
"successful": 1,
"failed": 0
},
"_seq_no": 0,
"_primary_term": 1
}
```
{% include copy-curl.html %}

### Step 4 (Optional): Retrieve the document

To retrieve the document, run the following query:

```json
GET logs/_doc/1
```
{% include copy-curl.html %}

#### Response

The following response shows the document with the modified `message` field value:

```json
{
"_index": "logs",
"_id": "1",
"_version": 1,
"_seq_no": 0,
"_primary_term": 1,
"found": true,
"_source": {
"message": "This is an warning message"
}
}
```
{% include copy-curl.html %}


2 changes: 1 addition & 1 deletion _ingest-pipelines/processors/index-processors.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ To set up and deploy ingest processors, make sure you have the necessary permiss

## Supported processors

Processor types and their required or optional parameters vary depending on your specific use case. OpenSearch supports the following ingest processors. For tutorials on using these processors in an OpenSerch pipeline, go to each processor's respective documentation.
Processor types and their required or optional parameters vary depending on your specific use case. OpenSearch supports the following ingest processors. For tutorials on using these processors in an OpenSearch pipeline, go to each processor's respective documentation.

Processor type | Description
:--- | :---
Expand Down
155 changes: 155 additions & 0 deletions _ingest-pipelines/processors/script.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
---
layout: default
title: script
parent: Ingest processors
nav_order: 230
---

# Script processor

The `script` processor executes inline and stored scripts that can modify or transform data in an OpenSearch document during the ingestion process. The processor uses script caching for improved performance because scripts may be recompiled per document. Refer to [Script APIs](https://opensearch.org/docs/latest/api-reference/script-apis/index/) for information about working with scripts in OpenSearch.

The following is the syntax for the `script` processor:

```json
{
"processor": {
"script": {
"source": "<script_source>",
"lang": "<script_language>",
"params": {
"<param_name>": "<param_value>"
}
}
}
}
```
{% include copy-curl.html %}

## Configuration parameters

The following table lists the required and optional parameters for the `script` processor.

| Parameter | Required/Optional | Description |
|---|---|---|
`source` | Optional | The Painless script to be executed. Either `id` or `source` must be specified---but not both. If `source` is specified, then the script is executed using the provided source code.
`id` | Optional | The ID of a stored script previously created using the [Create Stored Script API]({{site.url}}{{site.baseurl}}/api-reference/script-apis/create-stored-script/). Either `id` or `source` must be specified, but not both. If `id` is specified, then the script source is retrieved from the stored script with the specified ID.
`lang` | Optional | The programming language of the script. Default is `painless`.
`params` | Optional | The parameters that can be passed to the script.
`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 processor failures. See [Handling pipeline failures]({{site.url}}{{site.baseurl}}/ingest-pipelines/pipeline-failures/).
`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. See [Handling pipeline failures]({{site.url}}{{site.baseurl}}/ingest-pipelines/pipeline-failures/).
`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-script-pipeline` that uses the `script` processor to convert the `message` field to uppercase:

```json
PUT _ingest/pipeline/my-script-pipeline
{
"description": "Example pipeline using the ScriptProcessor",
"processors": [
{
"script": {
"source": "ctx.message = ctx.message.toUpperCase()",
"lang": "painless",
"description": "Convert message field to uppercase"
}
}
]
}
```
{% 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-script-pipeline/_simulate
{
"docs": [
{
"_source": {
"message": "hello, world!"
}
}
]
}
```
{% 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": {
"message": "HELLO, WORLD!"
},
"_ingest": {
"timestamp": "2024-05-30T16:24:23.30265405Z"
}
}
}
]
}
```
{% include copy-curl.html %}

### Step 3: Ingest a document

The following query ingests a document into an index named `testindex1`:

```json
POST testindex1/_doc?pipeline=my-script-pipeline
{
"message": "hello, world!"
}
```
{% include copy-curl.html %}

#### Response

The response confirms that the document has been indexed into `testindex1` and has indexed all documents with the `message` field converted to uppercase:

```json
{
"_index": "testindex1",
"_id": "1",
"_version": 1,
"result": "created",
"_shards": {
"total": 2,
"successful": 1,
"failed": 0
},
"_seq_no": 6,
"_primary_term": 2
}
```
{% 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 %}

0 comments on commit ad46155

Please sign in to comment.