Scripted fields and fields not exists

Hi, I want in kibana created a scripted field to know a time of resolution of a project.

For that I writed this :


doc['fields.LastDate'].date.dayOfYear- doc['fields.Bugdate'].date.dayOfYear


And this functionned perfectly but I have lines In my index without this fields.

And I have an error like that:

And it says it's because some lines don't have this 2 fields for created this time of resolution.
And I can't see some lines in discover by this error.

For that I deleted my scripted field and like that I can see this other lines.
Now I want to recreated this field but I can't see everything lines and I have this explanation:

So I wanted for solved my first problem created an expression like that


(doc['fields.LastDate'].exists && doc['fields.Bugdate'].exists ) ? doc['fields.LastDate'].date.dayOfYear- doc['fields.Bugdate'].date.dayOfYear : 0


But this haven't functionned by le .exists do you have a means for created a field who say if the fields exists then do my first expression and if it not exists then return 0 ?
And can the resolution of the first problem solve the second?

Thanks for your help.

Hey @marie,
You get this expression because it´s a scripted field, scripted fields are not in the source-data and this says you that you can visualize and search on it, but you will not find this in your ES ( because its in Kibana).

You can write the following script to check if value is null

if(doc['myvalue.keyword']).value == null){
    return 0;
...Write your expression/painless script here here...

I have do the test but I still have 0 lines to display in discover and I have again this :


I would mean you have some messages where your field is not present.

Can you post your Script here, perhaps there is a typing failure?

I have test like that

if(doc['fields.LastDate'].value == null && doc['fields.Bugdate'].value==null){
return 0;
return doc['fields.LastDate'].date.dayOfYear- doc['fields.Bugdate'].date.dayOfYear;

and like that

(doc['fields.Lastdate'].value==null && doc['fields.Bugdate']==null)?0:doc['fields.LastDate'].date.dayOfYear- doc['fields.Bugdate'].date.dayOfYear

and the both does the same

Hmmm ok... What version have your ELK Stack ?

I have 6.1.2 version

So test around your scripts in the console, perhaps you get there the errors that helps you to find your failures inside your scripts.

I had this problem, too. The problem was that some of the fields that I used to calculate the scripted field had text which caused the script to fail. I soved it by calculating the value and adding it as a new field to the database, not as scripted field.

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