Scripted Fields in kibana not working

Scripted fields only calculate sum,length and count by line ,not the entire document this is my script below:

def sum = 0;
for (def i = 0; i < doc['Return_Code'].length; i++) {
sum = sum +doc['Return_Code'][i];
}
return sum;

and this the result:

I need to get 7 as values in the somme field so i can calculate the success rate 7/10=0.7 and show it in a metric any help please.

thank you!

It's possible to do this with the Time Series Visual Builder

I have used the following data to test against:

POST discuss-117661/doc
{
  "@timestamp": "2018-01-30T14:25:04",
  "Return_Code": 1,
  "somme": 1
}

POST discuss-117661/doc
{
  "@timestamp": "2018-01-30T14:25:04",
  "Return_Code": 1,
  "somme": 1
}

POST discuss-117661/doc
{
  "@timestamp": "2018-01-30T14:25:04",
  "Return_Code": 1,
  "somme": 1
}

POST discuss-117661/doc
{
  "@timestamp": "2018-01-30T14:25:04",
  "Return_Code": 0,
  "somme": 0
}

POST discuss-117661/doc
{
  "@timestamp": "2018-01-30T14:25:04",
  "Return_Code": 0,
  "somme": 0
}

POST discuss-117661/doc
{
  "@timestamp": "2018-01-30T14:25:04",
  "Return_Code": 0,
  "somme": 0
}

POST discuss-117661/doc
{
  "@timestamp": "2018-01-30T14:25:04",
  "Return_Code": 1,
  "somme": 1
}

POST discuss-117661/doc
{
  "@timestamp": "2018-01-30T14:25:04",
  "Return_Code": 1,
  "somme": 1
}

POST discuss-117661/doc
{
  "@timestamp": "2018-01-30T14:25:04",
  "Return_Code": 1,
  "somme": 1
}

POST discuss-117661/doc
{
  "@timestamp": "2018-01-30T14:25:04",
  "Return_Code": 1,
  "somme": 1
}

Create a new visualization using the Time Series Visual Builder.

First, select the Panel Options tab and enter the index pattern you would want to use.

Then, back on the Data tab, select use the Filter Ratio Aggregation. For the numerator, we will select the successful documents using Return_Code:1

thank you but it is showing 0 i don't know why , is there a way to do it and visualize it through scripted field ?

This is not possible with scripted fields. A scripted field is just that, a dynamic field on the document. It has no knowledge of other documents.

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