I am trinyg to run this script and it's not working as expected.
String messageValue = doc['message.keyword'];
if ( messageValue != null) {
String val = messageValue .substring(0,30);
return val + "678"; }
else { return "message is not there";}
In first return statement, if I simply return val, it's printing the correct value, but as soon as I do substring, I do not get anything back in the results.
Also, in the first line of the script, if I do doc['message.keyword'].value instead of doc['message.keyword'], it is returning null in some cases where as data is present in all the cases. I tried using def data type instead of String too, but even that worked the same way.
if I do doc['message.keyword'].value instead of doc['message.keyword'], it is returning null in some cases where as data is present in all the cases.
Are you sure? The doc map returns an accessor for a field, not the actual field value. That accessor is essentially a list over the values for that document, and it is empty if there are no values for that document. The accessor should not be null (it throws an error if the mapping does not exist). So I would rewrite your script as:
def messageValue = doc['message.keyword'];
if (messageValue.size() > 0) {
String val = messageValue.get(0).substring(0,30);
return val + "678";
} else {
return "message is not there";
}
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.