How to sort my time field in descending order with size 1 to get graph with only the latest documents?

Hi.
I have Vega-lite code for a graph in kibana.
I need to sort my time field in descending order with size 1 in order to get the documents belonging to the latest time.
I know I need to use the following lines, but I don't know how to combine them with the rest of the code:

"body": {
    "size": 10000,
    "aggs": {
        "time_field": {
            "terms": {
                "field": "Time",
                "size": 1,
                "order": {
                    "_key": "desc"
                }
            },
            "aggs": {
                "x_Field": {
                    "terms": {
                        "field": "x",
                        "size": 10000
                    }
                }
            }
        }
    }
}

And this is the code I have now:

{
  $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"}
    }  
}
}

If you can provide the Vega Spec (which will contain a sample of the data returned from the ES query) it would help us see what your data looks like in order to make a recommendation.

Unfortunately, I don't know how to do it without exposing business confidential data...

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