Hi Team,
while using scripted field in metricbeat index, I am getting StringIndexOutOfBoundsException: String index out of range: -1
error while searching. my created scripted field is:
if (doc.containsKey('beat.name') && doc['beat.name.keyword'].value != null && !doc['beat.name.keyword'].empty) {
return (doc['beat.name.keyword'].value.substring(0,doc['beat.name.keyword'].value.indexOf('-')));
}
return 'Undefined';
below is the log of elasticsearch:
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [?:1.8.0_45]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [?:1.8.0_45]
at java.lang.Thread.run(Thread.java:745) [?:1.8.0_45]
Caused by: java.lang.StringIndexOutOfBoundsException: String index out of range: -1
at java.lang.String.substring(String.java:1955) ~[?:1.8.0_45]
at org.elasticsearch.painless.PainlessScript$Script.execute(if (doc.containsKey('beat.name') && doc['beat.name.keyword'].value != null && !doc['beat.name.keyword'].empty) {
return (doc['beat.name.keyword'].value.substring(0,doc['beat.name.keyword'].value.indexOf('-')));
}
return 'Undefined';:195) ~[?:?]
at org.elasticsearch.painless.ScriptImpl.run(ScriptImpl.java:105) ~[?:?]
at org.elasticsearch.search.fetch.subphase.ScriptFieldsFetchSubPhase.hitsExecute(ScriptFieldsFetchSubPhase.java:66) ~[elasticsearch-6.1.1.jar:6.1.1]