Hello everyone,
I have a field that holds all the log information (multiple fields inside it).
Field looks like this: logging.level="some info", @timestamp="some info", message="some info", trace_id="some info"
I am trying, using scripted fields, to split the string into appropriate fields, but I encounter an error: A document doesn't have a value for a field! Use doc[].size()==0 to check if a document is missing a field!
The thing is that the field is not empty at all.
I have fixed it using the following: if (doc['message.keyword'].size() == 0) return "";
The error is gone but the newly created scripted field is showing as empty for obvious reasons.
Its seeing all fields as empty for some reasons.
This is my script without the line mentioned above.
String oldMessage = doc['message.keyword'].value;
def newScriptedField = "";
def index1 = oldMessage.indexOf('logging.level=');
def index2 = oldMessage.indexOf(', @');
if(oldMessage.contains("logging.level=")) {
newScriptedField = oldMessage.substring(index1 + 14, index2);
return newScriptedField;
} else {
return '';
}