Skip to content

Commit

Permalink
Expose URI parts processor in Painless (#73634) (#74714)
Browse files Browse the repository at this point in the history
  • Loading branch information
danhermann authored Jun 29, 2021
1 parent eb63472 commit 09043da
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,14 @@ public static String communityId(
icmpCode);
}

/**
* Uses {@link UriPartsProcessor} to decompose an URI into its constituent parts.
*
* @param uri string to decode
* @return Map containing URI components
*/
public static Map<String, Object> uriParts(String uri) {
return UriPartsProcessor.apply(uri);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ class org.elasticsearch.ingest.common.Processors {
String urlDecode(String)
String communityId(String, String, Object, Object, Object, Object, Object, Object, int)
String communityId(String, String, Object, Object, Object, Object, Object, Object)
Map uriParts(String)
}
Original file line number Diff line number Diff line change
Expand Up @@ -242,3 +242,38 @@ teardown:
- match: { _source.source_field: "foo" }
- match: { _source.target_field1: "1:hTSGlFQnR58UCk+NfKRZzA32dPg=" }
- match: { _source.target_field2: "1:LQU9qZlK+B5F3KDmev6m5PMibrg=" }

---
"Test invoke uri_parts processor":
- do:
ingest.put_pipeline:
id: "my_pipeline"
body: >
{
"description": "_description",
"processors": [
{
"script" : {
"lang": "painless",
"source" : "ctx.target_field = Processors.uriParts(ctx.source_field)"
}
}
]
}
- match: { acknowledged: true }

- do:
index:
index: test
id: 1
pipeline: "my_pipeline"
body: {source_field: "http://www.example.com/index.html"}

- do:
get:
index: test
id: 1
- match: { _source.source_field: "http://www.example.com/index.html" }
- match: { _source.target_field.scheme: "http" }
- match: { _source.target_field.domain: "www.example.com" }
- match: { _source.target_field.path: "/index.html" }

0 comments on commit 09043da

Please sign in to comment.