# Graph the last state of a case

**URL:** <https://discuss.elastic.co/t/graph-the-last-state-of-a-case/237040>\
**Category:** Kibana\
**Tags:** vega, kql-kibana-query-language\
**Created:** [June 14, 2020, 9:35pm UTC](https://discuss.elastic.co/t/graph-the-last-state-of-a-case/237040 "2020-06-14T21:35:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Katherinne\_Quintero](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/katherinne_quintero/32/42348_2.png) [@Katherinne\_Quintero](https://discuss.elastic.co/u/Katherinne_Quintero)\
**Post date:** [June 14, 2020, 9:35pm UTC](https://discuss.elastic.co/t/graph-the-last-state-of-a-case/237040/1 "2020-06-14T21:35:46Z")

</div>

I need to graph the last result of the cases and group them.

that is, how many cases do I currently have as a result in "en\_seguimiento", "sin\_respuesta" , or "SinVenta"...

In eslastic, a document is recorded for each result that a case has on time and a case can have a record with result x and then have a result y, so they handled this case.

what i need is to graph how many i currently have in the result "en\_seguimiento", "sin\_respuesta" , or "SinVenta"...

Currently I have a chart in kibana that tells me how many cases there have been for the different results, but it does not mean that it is the last result.

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/1/b/1bd745aed450daa6d19001c0e3823f7fbb421d9a.png)

I've been thinking of using Transforming and groups for case identification, but I don't know how to say that I only saved in the last record of this Transforming.

Does anyone have an idea how I can graph this in kibana?

The other thing that I have tried is to make this graph with Vega, since to obtain the last records of each case I think that I can have it for this query, but I find it difficult to graph it because the answer of the last case is staying within inner\_hits.

```
{ 
"query": {
"match_all": {}   
},
"collapse": {
"field": "caso_id.keyword",
"inner_hits": {
  "name": "most_recent",
  "size": 1,
  "sort": [{"caso_ts_ult_ges": "desc"}]
  }
 }
}
```

---

<div class="post-metadata">

**Author:** ![Hendrik\_Muhs](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hendrik_muhs/32/25802_2.png) [@Hendrik\_Muhs](https://discuss.elastic.co/u/Hendrik_Muhs)\
**Post date:** [June 16, 2020, 7:07am UTC](https://discuss.elastic.co/t/graph-the-last-state-of-a-case/237040/2 "2020-06-16T07:07:16Z")

</div>

> [@Katherinne\_Quintero](#):
>
> I've been thinking of using Transforming and groups for case identification, but I don't know how to say that I only saved in the last record of this Transforming.

There is an [example](https://www.elastic.co/guide/en/elasticsearch/reference/7.7/transform-painless-examples.html#painless-top-hits) for this in the documentation of transform.

---

<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:** [July 14, 2020, 7:07am UTC](https://discuss.elastic.co/t/graph-the-last-state-of-a-case/237040/3 "2020-07-14T07:07:17Z")

</div>

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