I am trying to create to some scripted fields using painless by capturing some "keyword" in the log field, which is a long text field. for example, I have bunch of the log fields:
"Error: Duplicate entry in user1"
"Error: Duplicate entry in user2"
"Error: Duplicate entry in user1"
"Error: Duplicate entry in user3"
"Error: Duplicate entry in user2"
"Error: Duplicate entry in user1"
"Error: Duplicate entry in user3"
The painless I was using:
if (doc['log.keyword'].value == 'Duplicate entry') {
return "match";
}
return "No match";
to only capture the "Duplicate entry" error message regardless of userID, I am sure I need to use regex to do that. I am just wondering if there is another way to do it without using the regex. Any suggestions.
Reviewing the Painless API Reference suggests that there is a String.Contains(CharSequence) function. Haven't tried it, but looks like exactly what you need.
Depending on data volumes, extracting for every document for every query might get slow and computationally expensive. If this is the case you might be better off performing this work at index time and store the result in a separate, real field.
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.