How to use split on script field on kibana

hi.
i wrote the painless script field on the kibana 5.6.1
it's not work /&/.split(param)

how to use the split on script field on new version

hi @xcl3721,

can you double check if you have enabled regex on your elasticsearch cluster? For more information, see here:

https://www.elastic.co/guide/en/elasticsearch/painless/current/painless-examples.html#modules-scripting-painless-regex

If it isn't enabled, you'll likely get an error that's something like:

Error: Request to Elasticsearch failed: {"error":{"root_cause":[{"type":"script_exception","reason":"compile error","script_stack":["/\\&/.split(doc['foo'].val ...","^---- HERE"],"script":"/\\&/.split(doc['foo'].value)","lang":"painless"}],"type":"search_phase_execution_exception","reason":"all shards failed","phase":"query","grouped":true,"failed_shards":[{"shard":0,"index":"foobar","node":"RHQOJfdSR2ODGBdyxOHtdQ","reason":{"type":"script_exception","reason":"compile error","script_stack":["/\\&/.split(doc['foo'].val ...","^---- HERE"],"script":"/\\&/.split(doc['foo'].value)","lang":"painless","caused_by":{"type":"illegal_state_exception","reason":"Regexes are disabled. Set [script.painless.regex.enabled] to [true] in elasticsearch.yaml to allow them. Be careful though, regexes break out of Painless's protection against deep recursion and long loops."}}}]},"status":500}

Also, you will need to escape that & if you try to match the actual character.

1 Like

thank you sir,you are right

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.