Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enabling regex support on AWS Managed ElasticSearch in painless scripts

I am trying to upload templates to my AWS managed ElasticSearch.

ElasticSearch responds with a 500 error complaining that I need to set script.painless.regex.enabled to true. I know that you cannot edit the elasticsearch.yml file directly, but is there anyway to allow for support of regex in painless scripts on AWS managed ES?

like image 366
Alex Avatar asked Nov 13 '17 18:11

Alex


1 Answers

There is no way yet to use regex under AWS ES cluster.

You can try to use StringTokenizer, as following example:

example value:

doc['your_str_field.keyword'].value = '{"xxx":"123213","yyy":"123213","zzz":"123213"}'

Painless script:

{
"script": {
"lang": "painless",
"inline": "String xxx = doc['your_str_field.keyword'].value; xxx = xxx.replace('{','').replace('}','').replace('\"','').replace(' ','');StringTokenizer tokenizer = new StringTokenizer(xxx, ',');tokenizer.nextToken();tokenizer.nextToken();StringTokenizer tokenizer_v = new StringTokenizer(tokenizer.nextToken(),':');tokenizer_v.nextToken();return tokenizer_v.nextToken();"
}
}

also, I needed to increase max_compilations_rate

PUT /_cluster/settings
{
"transient": {
  "script.max_compilations_rate": "500/1m"
}
}
like image 200
sharkguto Avatar answered Sep 22 '22 12:09

sharkguto