We use many ScriptQuery and ScriptField in our project, and provide inline scripts for them in painless language.
My question is, how can we validate these painless scripts? In other words, how to make sure that they will compile?
The approach we use today is to test them out locally through Kibana. However, this is manual, error prone and not scalable. I am looking for a programmatic way or utility to validate painless scripts, so that I can plug it into the CI/CD pipeline. Is the compiler Elasticsearch uses under the hood open source ? Or is there some other way?
Elasticsearch version 5.4
Sample Query in Kibana with Painless script used for ScriptField and ScriptQuery
GET myIndex/_search
{
"script_fields": {
"LastName": {
"script": {
"inline": "if(doc['Author']!= null && doc['Author'].value != null){return doc['Author'].value.toUpperCase();}return null;",
"lang": "painless"
}
}
},
"query": {
"bool": {
"must_not": [
{
"bool": {
"must": [
{
"script": {
"script": {
"inline": "def lastName = '';if(doc['Author']!= null && doc['Author'].value != null){lastName = doc['Author'].value.toUpperCase();}if(doc.containsKey('LastName') && doc['LastName']!= null && doc['LastName'].value != null){lastName = doc['LastName'].value;}return (lastName.toLowerCase().startsWith(params.SearchParam.toLowerCase()));",
"lang": "painless",
"params": {
"SearchParam": "d"
}
}
}
}
]
}
}
]
}
}
}