# Table visualisation on last occurrence of specific field

**URL:** <https://discuss.elastic.co/t/table-visualisation-on-last-occurrence-of-specific-field/233290>\
**Category:** Kibana\
**Created:** [May 19, 2020, 10:03am UTC](https://discuss.elastic.co/t/table-visualisation-on-last-occurrence-of-specific-field/233290 "2020-05-19T10:03:22Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Max\_Bertolini](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/max_bertolini/32/68614_2.png) [@Max\_Bertolini](https://discuss.elastic.co/u/Max_Bertolini)\
**Post date:** [May 19, 2020, 10:03am UTC](https://discuss.elastic.co/t/table-visualisation-on-last-occurrence-of-specific-field/233290/1 "2020-05-19T10:03:22Z")

</div>

Hi Everybody,

I'm collecting data from an application that runs "jobs" on different users. The same jobs can be executed multiple times for the same user and I'm struggling to find a way to create a table visualisation that reports some stats taking care only of the last job execution for user.

here an example of the source data:  
jobId,user,jobname,jobresult,jobstatus,timestamp  
1,userA,BulkJob,IOException,ERROR,20200517120000  
**2,userA,FinalJob,Success,OK,20200517123000**  
**1,userA,BulkJob,Success,OK,20200517123500**  
3,userB,BulkJob,IOException,ERROR,20200517124000  
**3,userB,BulkJob,TimeoutException,ERROR,20200517124500**

What I'm trying to generate is a table that reports the success Failures of each jobname based only on the last execution of jobid. This means that only the bold raw should be reported.  
Expected result:  
Jobname | SUCCESS | ERROR  
BulkJob. | 1. | 1  
FinalJob. |. 1. |. 0

To count the SUCCESS and ERROR I used two "SUM" metrics with a JSON.input like this:  
{  
"script": {  
"inline": "doc['''jobStatus.keyword'''].value == '''OK''' ? 1 : 0",  
"lang": "painless"  
}  
}  
and  
{  
"script": {  
"inline": "doc['''jobStatus.keyword'''].value == '''ERROR''' ? 1 : 0",  
"lang": "painless"  
}  
}

and then a buckets "terms" aggregation on the filed jobName.  
But it's obviously counting all the occurrence not jus the last one...  
Any ideas?  
Thanks in advance.

Max

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [June 16, 2020, 10:03am UTC](https://discuss.elastic.co/t/table-visualisation-on-last-occurrence-of-specific-field/233290/2 "2020-06-16T10:03:23Z")

</div>

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