-
Notifications
You must be signed in to change notification settings - Fork 625
Adding example to contains data prepper #11356
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
base: main
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,7 +18,7 @@ | |
| For example, if you want to check if the string `"abcd"` is contained within the value of a field named `message`, you can use the `contains()` function as follows: | ||
|
|
||
| ``` | ||
| contains('/message', 'abcd') | ||
| 'contains(/message, "abcd")' | ||
| ``` | ||
| {% include copy.html %} | ||
|
|
||
|
|
@@ -27,11 +27,89 @@ | |
| Alternatively, you can use a literal string as the first argument: | ||
|
|
||
| ``` | ||
| contains('This is a test message', 'test') | ||
| 'contains("This is a test message", "test")' | ||
| ``` | ||
| {% include copy.html %} | ||
|
|
||
| In this case, the function returns `true` because the substring `test` is present within the string `This is a test message`. | ||
|
|
||
| The `contains()` function performs a case-sensitive search. | ||
| {: .note} | ||
|
|
||
| ## Example | ||
|
|
||
| The following pipeline uses `contains()` to add a boolean flag `has_test` based on a substring in `/message` and to filter out non-matching events, forwarding only messages containing "ERROR" to OpenSearch: | ||
|
Check failure on line 41 in _data-prepper/pipelines/contains.md
|
||
|
|
||
| ```yaml | ||
| contains-demo-pipeline: | ||
| source: | ||
| http: | ||
| ssl: false | ||
|
|
||
| processor: | ||
| - add_entries: | ||
| entries: | ||
| - key: "has_test" | ||
| value_expression: 'contains(/message, "test")' | ||
|
||
| - drop_events: | ||
| drop_when: 'not contains(/message, "ERROR")' | ||
|
|
||
| sink: | ||
| - opensearch: | ||
| hosts: ["https://opensearch:9200"] | ||
| insecure: true | ||
| username: admin | ||
| password: "admin_pass" | ||
|
||
| index_type: custom | ||
| index: "demo-index-%{yyyy.MM.dd}" | ||
| ``` | ||
| {% include copy.html %} | ||
| You can test the pipeline using the following command: | ||
| ```bash | ||
| curl -sS -X POST "http://localhost:2021/events" \ | ||
| -H "Content-Type: application/json" \ | ||
| -d '[ | ||
| {"message":"ok hello"}, | ||
| {"message":"this has test but ok"}, | ||
| {"message":"ERROR: something bad"}, | ||
| {"message":"ERROR: unit test failed"} | ||
| ]' | ||
| ``` | ||
| {% include copy.html %} | ||
|
|
||
| The documents stored in OpenSearch contain the following information: | ||
|
|
||
| ```json | ||
| { | ||
| ... | ||
| "hits": { | ||
| "total": { | ||
| "value": 2, | ||
| "relation": "eq" | ||
| }, | ||
| "max_score": 1, | ||
| "hits": [ | ||
| { | ||
| "_index": "demo-index-2025.10.21", | ||
| "_id": "5YACB5oBqZitdAAb4n3r", | ||
| "_score": 1, | ||
| "_source": { | ||
| "message": "ERROR: something bad", | ||
| "has_test": false | ||
| } | ||
| }, | ||
| { | ||
| "_index": "demo-index-2025.10.21", | ||
| "_id": "5oACB5oBqZitdAAb4n3r", | ||
| "_score": 1, | ||
| "_source": { | ||
| "message": "ERROR: unit test failed", | ||
| "has_test": true | ||
| } | ||
| } | ||
| ] | ||
| } | ||
| } | ||
| ``` | ||
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.
Let's remove unnecessary quotes. I suggest this because the abundance of quotes we already have in our documentation is leading to double quotes on the expressions. As you've probably already noticed, this makes it hard to write expressions.