TSVB: Create time series graph which based on latest document in each bucket

Hi All.
I need your help, I just started working with Elasticsearch and Kibana.
I have an Index with the following mapping:

  "mapping": {
    "_doc": {
      "properties": {
        "pending_tasks": {
          "type": "integer"
        "type": {
          "type": "keyword"
        "updated_at": {
          "type": "date"

'pending_tasks' is number of tasks wait in the queue.
'type' represent the queue type. let say it can be one of ['A', 'B', C'].
'updated_at' represent the date/time this document created.

So to my question:
I first split all documents to buckets (based on date histogram).
Now I want to maintain in each bucket only the last document per type (['A', 'B', C']), and ignore the rest of the documents in each bucket.
How can I do this???

Now to be more kibana (TSVB) oriented:
I want to create a chart in Kibana based on TSVB tool, that show the pending tasks over time for each of the types ['A', 'B', C'].
The data for the number of pending task per type inr each bucket is store in the latest documents in each bucket.
Please help.

I think what you want to do in TSVB is use the Terms aggregation to split the type field, and then you want to use the Top Hits aggregation to select only the most recent document per type. You must select a numeric field from this document, such as pending_tasks: but this should work.

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