Skip to content
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 a test for regex usage to runtime fields #63951

Merged
merged 1 commit into from
Oct 20, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,20 @@ setup:
runtime_type: ip
script:
source: |
String m = doc["message"].value;
int end = m.indexOf(" ");
emit(m.substring(0, end));
Matcher m = /([^ ]+) .+/.matcher(doc["message"].value);
if (m.matches()) {
emit(m.group(1));
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

out of curiosity, what happens when matches returns false for a doc? the runtime field wont have any value thats it?

# Test fetching from _source
ip_from_source:
type: runtime
runtime_type: ip
script:
source: |
String m = params._source.message;
int end = m.indexOf(" ");
emit(m.substring(0, end));
Matcher m = /([^ ]+) .+/.matcher(params._source.message);
if (m.matches()) {
emit(m.group(1));
}
# Test emitting many values
ip_many:
type: runtime
Expand Down Expand Up @@ -71,9 +73,10 @@ setup:
- match: {http_logs.mappings.properties.ip.runtime_type: ip }
- match:
http_logs.mappings.properties.ip.script.source: |
String m = doc["message"].value;
int end = m.indexOf(" ");
emit(m.substring(0, end));
Matcher m = /([^ ]+) .+/.matcher(doc["message"].value);
if (m.matches()) {
emit(m.group(1));
}
- match: {http_logs.mappings.properties.ip.script.lang: painless }

---
Expand Down