Scripted Field in Kibana to extract from a nested document structure

Hi all

Kibana and ES 7.7.0

My doc structure is like this:

{
"key1": "value1",
"key2": "value3",
"key3": {
"key4": {
"key5": "value5",
"key6": "val6/val7/val8/val9.html"
},
"key7": "val10"
},
"key8": "val11",
"key9": "val12"
}

I need to add a scripted_field in my index pattern that basically gives me "val9"

If I were to write the logic in python
my_val = doc['key3']['key4']['key6'][::-1].split('/')[0][::-1].split('.')[0]
return my_val

How do I do this in Painless ?

Thanks
warmly

sanjay

I figured out how to do this. Sharing my solution with all.
Thanks
warmly
sanjay

String htmlStr = doc['key3.key4.key6'].value;
StringBuffer sb1 = new StringBuffer(htmlStr);
sb1.reverse();
String htmlStr2 = /\//.split(sb1.toString())[0];
StringBuffer sb2 = new StringBuffer(htmlStr2);
sb2.reverse();
String htmlStr3 = /\./.split(sb2.toString())[0];
return htmlStr3;

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