Scripted field for Matching Substring

Hi,

My setup:
Kibana 5.6.2
ES 5.6.2

Need some help to extract the SIM number from the path field in a document
The field value:

C:/HWM/Apps/CAR/Export/971XXXXXX231_20180903.CSV

I need to fetch only the value 971XXXXXX231 as a result for the below mentioned scripted field.

Here is my attempt using the examples mentioned in scripted help

def logger= doc['path.keyword'].value;
if (logger!= null) {
    int lastSlashIndex = logger.lastIndexOf('/');
    if (lastSlashIndex > 0) {
    return logger.substring(lastSlashIndex+1);
    }
}
return "";

But the result is 971XXXXXX231_20180903.CSV

Fixed it myself.

def logger= doc['path.keyword'].value;
if (logger!= null) {
    int lastSlashIndex = logger.lastIndexOf('/');
    int lastUndrIndex = logger.lastIndexOf('_');
    if (lastSlashIndex > 0) {
    return logger.substring(lastSlashIndex+1,lastUndrIndex);
    }
}
return "";

Hey @karnamonkster, I'm glad to hear you were able to solve your issue, thanks for sharing your solution here for others!

1 Like

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