I have a field "a" that sometimes gets values that satisfy the following pattern: "AAA_BBB_CCC_DDD".
The relevant feature of this pattern is the occurrence of the four underscores "_". The lenght of the A's, B's, C's and D's may vary.
I'm trying to define a scripted field that provides a certain output when the value of field "a" satisfies this pattern (i.e. contains four underscores). The problem is that I'm not describing the pattern correctly.
My idea is:
def c ="";
def b = doc['a.keyword'].value;
def first = b.indexOf('_');
if (doc['a.keyword'].value=='*_*_*_*')
{c = b.substring(0,first);}
else {c = 0;}
return c
This scripted field now outputs 0 for all entries and this shouldn't be the case. The condition(doc['a.keyword'].value=='*_*_*_*')
is never satisfied, which implies that the relevant pattern is not being well described by '*_*_*_*'
.
Any ideas or suggestions on how to do this?
Thanks in advance