IMPORTANT: No additional bug fixes or documentation updates
will be released for this version. For the latest information, see the
current release documentation.
Conditionals with the Regular Expressions
edit
IMPORTANT: This documentation is no longer updated. Refer to Elastic's version policy and the latest documentation.
Conditionals with the Regular Expressions
editThe if conditional is implemented as a Painless script. If the
script.painless.regex.enabled cluster
setting is enabled, you can use regular expressions in your if condition
scripts. For supported syntax, see Painless
regular expressions.
PUT _ingest/pipeline/check_url
{
"processors": [
{
"set": {
"if": "ctx.href?.url =~ /^http[^s]/",
"field": "href.insecure",
"value": true
}
}
]
}
POST test/_doc/1?pipeline=check_url
{
"href": {
"url": "http://www.elastic.co/"
}
}
Results in:
{
"_index": "test",
"_type": "_doc",
"_id": "1",
"_version": 1,
"_seq_no": 60,
"_primary_term": 1,
"found": true,
"_source": {
"href": {
"insecure": true,
"url": "http://www.elastic.co/"
}
}
}
Regular expressions can be expensive and should be avoided if viable alternatives exist.
For example in this case startsWith can be used to get the same result
without using a regular expression:
PUT _ingest/pipeline/check_url
{
"processors": [
{
"set": {
"if": "ctx.href?.url != null && ctx.href.url.startsWith('http://')",
"field": "href.insecure",
"value": true
}
}
]
}