Scripted field to get next doc value in Kibana using painless script

Hi Team,

Below is the sample scripted field we use in Kibana side. What I would like to receive is, when path becomes null, I would like to read next document value.(something like path = doc['message.keyword']+1.value;)

Is it possible to read? If so, how? I almost spent few hours but no luck.

def path = doc['message.keyword'].value;
    if(path == null) {
.....
....

Any reply would be appreciated

I am not sure I understand what you are looking to achieve. Can you provide 2 full sample documents, with and without the path field set, and show us what you would expect the result to be?