Scripted field

Hi ,

I am trying to substract to date format vales through scripted field in kibana scripted fileds

if(doc['response_time'] > doc['request_time']){
    return doc['response_time'].value.getMillis() - doc['request_time'].value.getMillis();
}

But it gives me the error ```
Cannot apply [>] operation to types [org.elasticsearch.index.fielddata.ScriptDocValues.Dates] and [org.elasticsearch.index.fielddata.ScriptDocValues.Dates]




Regards,
Neha Changra

Hi

You could try it the following way (can be further improved by using variables)

if(doc['response_time'].value.getMillis() > doc['request_time'].value.getMillis()){
    return doc['response_time'].value.getMillis() - doc['request_time'].value.getMillis();
}

Hope this helps,
Best,
Matthias

Hi Team,

I have been to substract the date value and store the value in the variable defined as " duration" and then check if the value is smaller than 2 then return a value through scripted filed in kibana

    if (doc['request_time'].size()!=0 && doc['response_time']!=0 && doc['response_time'].value.getMillis() > doc['request_time'].value.getMillis())
            {
        return doc['response_time_milli'].value.getMillis() - doc['request_time_milli'].value.getMillis()= doc['duration'].value.getMillis();
            }
               if (doc['duration'].value.getMillis() < 2)
               {
                return   doc['duration_2'].value.getMillis() = 1;
               }

although i get an error

```
"script": "if (doc['request_time'].size()!=0 && doc['response_time']!=0 && doc['response_time'].value.getMillis() > doc['request_time'].value.getMillis())\n        {\n    return doc['response_time_milli'].value.getMillis() - doc['request_time_milli'].value.getMillis()= doc['duration'].value.getMillis();\n        }\n           if (doc['duration'].value.getMillis() < 2)\n           {\n            return   doc['duration_2'].value.getMillis() = 1;\n           }\n ",
"lang": "painless",
"caused_by": {
 "type": "illegal_argument_exception",
 "reason": "Left-hand side cannot be assigned a value."
}




    Regards,
Neha Changra

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