I am trying to create a scripted field to be able to fetch me the first value of a certain field.
I find the problem in that when it returns the values of the field, and I save them in path, it sorts them alphabetically in such a way that when choosing the zero value later, this is sometimes not the one I want.
I would like to get the values in the same order as in the original field.
//
if (!doc.containsKey('RSLT') || doc['RSLT'].empty){
return ""
}else{
def list = [];
for(int i=0; i < doc['RSLT'].length;i++){
def path=doc['RSLT'][i];
int lastSlashIndex = path.lastIndexOf(':');
if (lastSlashIndex > 0) {
list.add(path.substring(lastSlashIndex+1));
}else {
list.add(path);
}
}
return list[0];
}
//
Can you make an example (with input and output) of what you would like to achieve vs what you are seeing with the current version of the script? It's not clear to me from the screenshot you posted.
If original field = {route:INCIDENCIA_TECNICA_ADSL}, {route:ADSL_CONCRETAR}
I want to get value in position 0 INCIDENCIA_TECNICA_ADSL
but I obtain ADSL_CONCRETAR because : def path=doc['RSLT'][i] order the values.
Thanks
Hi Joe:
could you help me with the script? I don't know how to enter the new parameter that you tell me to make it work for me.
I do not have much experience with painless and all help is great
Regards
The scripted field is defined using the painless programming language, and extracting a part of a string is a simple task in this programming language. See the official guide for how to do string manipulation: Painless Guide | Painless Scripting Language [7.11] | Elastic
The script in your original question is pretty close to what you need.
I won't write your script for you, please check out the tutorials to learn how to use the painless programming language for this kind of simple tasks.
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.