Scripted Field "String, in between two strings"

I have a field I need to query to get a value. the text in the field, is a string a couple of hundred characters long, and I need 4 characters, which are smack in the middle.

I have tried get substring, but I can only get it to show the data I'm looking for, and the 100+ characters after what I need.
Is there a way to get the substring, and then only return the first X number of characters of the string?
Or even better, get substring, between two "strings".

I gave Regex a go, and had no luck with that either.

The only thing I can provide as a "thing to trigger on" is
the br549 in the line below is the data I am looking to populate into the scripted field, and the data immediately before and after, is always the same

D;+ID=br549;+Client=

This gets me data, starting at br549, and then the rest of the field after that.

def path = doc['FIeld.keyword'].value;
int lastIDIndex = path.lastIndexOf('ID=');
if (lastIDIndex > 0) {
return path.substring(lastIDIndex+4);
}
return "";

Thanks in advance

If you're wanting to search for this frequently, I would highly recommend getting this data at index time. This can be accomplished at the application layer, or with Elasticsearch Ingest or Logstash.

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