Static variables in Kibana discovery script

What should be something very simple.
I want to create a new field for a Kibana discovery and dashboard that simply counts the received document. So each document will have an index 0, 1, 2, ..., n. However, I do not see anyway to initialize a static field so I can do something simple like

int index = static_index;  // I need this initialized at the beginning of the search and not after
index++
static_index = index;
return index;

Is it possible to make two scripts and access my static field using

int index = doc["my_static_field"].value()
index++
doc['my_static_field'].value() = index

where 'my_created_field' is my static value

Hi @gyannea. I don't believe it is possible to increment a variable in a field. Variables defined in a runtime field are limited to the scope of the returned document.

Can you explain why you want to define an index field? Maybe we can figure out another solution.

I am trying to get as close as possible to the user-entered timepicker values so I can compute things like the 'percent of time cellular connectivity was down' over the user-specified interval. There is no way to get that range from a script. It was asked for back in 2017 and the responder said to submit an enhancement request but as far as I know it has not been done.

If I could create a 'count' for each document received from 1 to N in time order, I could use the time stamp of the document with count 1 as the start time and document N as the end time. Not exactly the same, but the best I can do.

Thanks for the additional information. Does each document have date fields that indicate when connectivity was lost and then gained? Or do you record connectivity connection/losses in separate documents?

Either way, I don't think it's possible to accomplish this by adding a field in Discover. But it might be possible to use a Lens visualization with formulas.

They do, but if there is only one such event in the middle of June you won't be able to report what percentage of the time that there was connectivity during the month of June. Of course we would like NO events so we could report 100% but that is an unlikely scenario unless the time period is pretty short.

The month of June is just an example of a user-selected time period. It can be anything (a year, a day, a week, etc.)

I understand. Sorry, I don't have any other ideas at this time. Would you be willing to provide any example documents and index mapping? Maybe that would trigger some ideas. But we could also be running into a feature gap that we just can't solve at this time.

I'm not exactly sure how to do that sharing ... but in the end I am pretty sure you cannot do this relying just on the archived documents. Access to that user input is essential. (I see that the Kibana searches access that range of course!)

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