Painless script. Illegal list shortcut value [value]. For try to stup field variable

Hello all,

I tried with Painless script to create a new field from another field.

I have this code

if(doc['name.keyword'].size()!=0){
      def p =/[^\/]+\/([^\/]+)/;
      def m = p.matcher(doc['name.keyword'].value);
       if (m.find()) {
        doc['test_name.keyword'].value = m.group(1);
        return m.group(1);
      }
}

If i use only the return is correct is show the correct text on the kibana but i want also to be on the _doc

The error:

Caused by: java.lang.IllegalArgumentException: Illegal list shortcut value [value].
        at org.elasticsearch.painless.Def.lookupSetter(Def.java:443) ~[?:?]
        at org.elasticsearch.painless.DefBootstrap$PIC.lookup(DefBootstrap.java:156) ~[?:?]
        at org.elasticsearch.painless.DefBootstrap$PIC.fallback(DefBootstrap.java:208) ~[?:?]
        at org.elasticsearch.painless.PainlessScript$Script.execute(if(doc['name.keyword'].size()!=0){ ...:201) ~[?:?]
        at org.elasticsearch.search.fetch.subphase.ScriptFieldsFetchSubPhase.hitsExecute(ScriptFieldsFetchSubPhase.java:67) ~[elasticsearch-7.1.1.jar:7.1.1]
        at org.elasticsearch.search.fetch.FetchPhase.execute(FetchPhase.java:177) ~[elasticsearch-7.1.1.jar:7.1.1]
        at org.elasticsearch.search.SearchService.lambda$executeFetchPhase$3(SearchService.java:540) ~[elasticsearch-7.1.1.jar:7.1.1]
        at org.elasticsearch.search.SearchService$3.doRun(SearchService.java:380) ~[elasticsearch-7.1.1.jar:7.1.1]
        at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37) ~[elasticsearch-7.1.1.jar:7.1.1]
        at org.elasticsearch.common.util.concurrent.TimedRunnable.doRun(TimedRunnable.java:41) ~[elasticsearch-7.1.1.jar:7.1.1]
        at org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.doRun(ThreadContext.java:751) ~[elasticsearch-7.1.1.jar:7.1.1]

I'm not sure if it's completely related but it seems you should be returning something in the case that the matcher does not match as well.

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