-
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 pattern_capture token filter docs #8240 #8260
Merged
kolchfa-aws
merged 5 commits into
opensearch-project:main
from
AntonEliatra:adding-pattern-capture-token-filter-docs
Nov 25, 2024
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
630f33d
adding pattern_capture token filter docs #8240
AntonEliatra fe9df50
updating parameter table
AntonEliatra 46045f0
Doc review
kolchfa-aws 1e8debe
Apply suggestions from code review
kolchfa-aws 3b3fed5
Merge branch 'main' into adding-pattern-capture-token-filter-docs
kolchfa-aws 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
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,97 @@ | ||
--- | ||
layout: default | ||
title: Pattern capture | ||
parent: Token filters | ||
nav_order: 310 | ||
--- | ||
|
||
# Pattern capture token filter | ||
|
||
The `pattern_capture` token filter is a powerful filter that uses regular expressions to capture and extract parts of text according to specific patterns. This filter can be useful when you want to extract particular parts of tokens, such as email domains, hashtags, or numbers, and reuse them for further analysis or indexing. | ||
|
||
## Parameters | ||
|
||
The `pattern_capture` token filter can be configured with the following parameters. | ||
|
||
Parameter | Required/Optional | Data type | Description | ||
:--- | :--- | :--- | :--- | ||
`patterns` | Required | Array of strings | An array of regular expressions used to capture parts of text. | ||
`preserve_original` | Required | Boolean| Whether to keep the original token in the output. Default is `true`. | ||
|
||
|
||
## Example | ||
|
||
The following example request creates a new index named `email_index` and configures an analyzer with a `pattern_capture` filter to extract the local part and domain name from an email address: | ||
|
||
```json | ||
PUT /email_index | ||
{ | ||
"settings": { | ||
"analysis": { | ||
"filter": { | ||
"email_pattern_capture": { | ||
"type": "pattern_capture", | ||
"preserve_original": true, | ||
"patterns": [ | ||
"^([^@]+)", | ||
"@(.+)$" | ||
] | ||
} | ||
}, | ||
"analyzer": { | ||
"email_analyzer": { | ||
"tokenizer": "uax_url_email", | ||
"filter": [ | ||
"email_pattern_capture", | ||
"lowercase" | ||
] | ||
} | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
{% include copy-curl.html %} | ||
|
||
## Generated tokens | ||
|
||
Use the following request to examine the tokens generated using the analyzer: | ||
|
||
```json | ||
POST /email_index/_analyze | ||
{ | ||
"text": "[email protected]", | ||
"analyzer": "email_analyzer" | ||
} | ||
``` | ||
{% include copy-curl.html %} | ||
|
||
The response contains the generated tokens: | ||
|
||
```json | ||
{ | ||
"tokens": [ | ||
{ | ||
"token": "[email protected]", | ||
"start_offset": 0, | ||
"end_offset": 20, | ||
"type": "<EMAIL>", | ||
"position": 0 | ||
}, | ||
{ | ||
"token": "john.doe", | ||
"start_offset": 0, | ||
"end_offset": 20, | ||
"type": "<EMAIL>", | ||
"position": 0 | ||
}, | ||
{ | ||
"token": "example.com", | ||
"start_offset": 0, | ||
"end_offset": 20, | ||
"type": "<EMAIL>", | ||
"position": 0 | ||
} | ||
] | ||
} | ||
``` |
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 "part" the right word here?
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.
Yup, it's the proper term https://en.wikipedia.org/wiki/Email_address