Scripted field in kibana (painless)

Hello everyone,

I'm trying to create a simple scripted field in my index of ES. Basically, I have a field "attempResult" in my index that could be null when the grok(logstash pattern) does not match, or "Successful", "Failed" in the cases in which the pattern match.

So, what I would like is to create a field (number) with the value of 1 when the field 'attemptResult' is "failed", and 0 in the case it is "Successful". I'm trying to create that on the script section of the scripted field definition by using :slight_smile:

if(doc['attemptResult.keyword'] == ("Sucessful")){
return 0;
}
if(doc['attemptResult.keyword'] == ("Failed")){
return 1;
}

but when i run it, it always adds null value to the scripted field,

any suggestion?

Thanks su much,

JUAN DAVID BRICENO GUERRERO
MASTER STUDENT IN SUSTAINABLE INDUSTRIAL ENGINEERING

When the value is null, what would you like it to return, null, 1 or 0?

I assume you want it always to return 1 or 0. In that case, you could modify the scripted field to return 0 when successful, and 1 otherwise:

if(doc['attemptResult.keyword'] == ("Sucessful")){
return 0;
}

return 1;

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