Plot only documents with the latest time

I have an index in with time field, and for each time there are multiple documents.
I want to present only the results of the latest time. how can I do it?
Is there a way to calculate the maximum value of the time field over all documents, and then apply a filter based on this value?

here is an example of the code:

{
  $schema: https://vega.github.io/schema/vega-lite/v2.json

  data: {
    data: table
    url: {
      %context%: true
      %timefield%: Time
      index: data*
      body: {
        size: 10000
        _source: ["X", "Y"]
      }
    }
    format: {property: "hits.hits"}
  }
  mark: {type: "square", filled: true, size: 800 }
encoding: {
    x: {
      field: "_source.X"
      type: quantitative
      axis: {title: "X"}
    }
    y: {
      field: "_source.Y"
      type: quantitative
      axis: {title: "Y"}
    }  
}
}

Use a terms aggregation to group your documents. Then use top hits aggregation aggregation to only get a single document per term.

Thank you for your reply.
But for a given Time value there are multiple documents, and I need all of them.
and after visiting the link you sent, I am not sure where and how I should add these lines to my code.
is it in the "body" section?

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