Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in AWS by (19.1k points)

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 any way to allow for support of regex in painless scripts on AWS managed ES?

1 Answer

0 votes
by (44.4k points)

You cannot use the regex under the AWS ES cluster, but instead, you can use a StringTokenizer:

example value:

doc['your_str_field.keyword'].value = '{"xxx":"12321321","yyyy":"34123213","zzzz":"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, you will need to increase max_compilations_rate

PUT /_cluster/settings

{

"transient": {

  "script.max_compilations_rate": "500/1m"

}

}

Related questions

Want to get 50% Hike on your Salary?

Learn how we helped 50,000+ professionals like you !

0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...