Calculated field not working

Hi all,

I am trying to create a simple calculated field by a simple subtraction of two fields within the same index. My query looks something like this:

{
"_source": {
"includes": [ "realTimestamp", "clientDelay", "networkDelay"]
},
"query": {
"range": {
"realTimestamp": {
"gte": "06/05/2018 00:00:00",
"lt": "06/05/2018 23:59:59"
}
}
},
"script_fields": {
"browserDelay": {
"script": {
"lang": "painless",
"source": "doc['clientDelay'].value - doc['networkDelay'].value;"
}
}
}
}

But the results looks like this:

"_source": {
"realTimestamp": "06/05/2018 23:59:43",
"networkDelay": 0.834,
"clientDelay": 1.058
},
"fields": {
"browserDelay": [
1
]
}

Seems that the output of the calculate is a simple integer rather that a decimal. I also tried the following but I got the same result.

{
"_source": {
"includes": [ "realTimestamp", "clientDelay", "networkDelay"]
},
"query": {
"range": {
"realTimestamp": {
"gte": "06/05/2018 00:00:00",
"lt": "06/05/2018 23:59:59"
}
}
},
"script_fields": {
"browserDelay": {
"script": {
"lang": "painless",
"source": "float browserDelay; browserDelay = doc['clientDelay'].value - doc['networkDelay'].value; return browserDelay;"
}
}
}
}

Any reason what seems the results to be round up?

"_source": {
"realTimestamp": "06/05/2018 23:59:40",
"networkDelay": 0.787,
"clientDelay": 2.161
},
"fields": {
"browserDelay": [
2
]
}

Thanks in advance,

Zareh

Hi Zareh,

This does seem strange. I'm curious as to what the values of clientDelay and networkDelay are within the script. Would you please try running the a couple of debugging scripts:

  1. "Debug.explain(doc['clientDelay'].value);"
  2. "Debug.explain(doc['networkDelay'].value);"

Thanks,
Jack

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