Skip to content

Commit

Permalink
Add a test for regex usage to runtime fields (elastic#63951)
Browse files Browse the repository at this point in the history
Now that we've got regexes enabled by default (elastic#63029) this adds a test
to runtime fields just to make sure that it works with regexes. It does,
but this adds a test to make sure it continues to work.
  • Loading branch information
nik9000 committed Oct 20, 2020
1 parent 25e2d31 commit ffed069
Showing 1 changed file with 12 additions and 9 deletions.
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));
}
# 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

0 comments on commit ffed069

Please sign in to comment.