OK. So my mistake was thinking that emit instantly returned. But it doesn't. So my triple check here for containsKey and not empty and not size == 0 is a bit overkill, but it works if I use them correctly. So with this I have a runtime field of type Long (integer) which is +1 when an issue is opened, -1 when an issue is closed, and 0 for any other action.
if (doc.containsKey('action.keyword')) {
if (!(doc['action.keyword'].empty)) {
if (!(doc['action.keyword'].size() == 0)) {
def action = doc['action.keyword'].value;
if (action == "opened") {
emit(1);
} else if (action == "closed") {
emit(-1);
} else emit(0);
}
}
}
Then I create a new Lens visualization and use Cumulative sum aggregation on that runtime field over time;
I'm still trying to figure out why I have multiple closed action docs for some issues. Until I resolve that this data is invalid for me. But hopefully on your Jira data you can isolate single opened and closed events per issue.
I can use a filter to only get docs where the action.keyword is opened or closed but it doesn't change the chart any since I'm setting the runtime field to 0 for anything else.
This simple visualization isn't matching the issue numbers. So the results are really aggregate data of how many were opened vs how many closed since the start of the time span. You could, for example, pick a start date after a bunch of issues were opened and before they were closed and get a negative cumulative sum. If you set your start time back before your very first issue was opened, the final cumulative sum should end with the number of issues currently open.
Some other visualization types besides Lens might also support the cumulative sum.
Regards,
Lee
