Is it possible to get the %timefield% value on vega script

It possible using a workaround. Somewhere in your request query you can specify the meta property as part of an agg:

aggs: {
                      time: {
                        min: {
                          field: kubernetes.event.timestamp.first_occurrence
                        }
                        meta: {
                          bounds: {
                            %timefilter%: min
                          }
                        }
                      }
                    }

Elasticsearch will reflect the meta information in the response:

"aggs": {
                      "time": {
                        "min": {
                          "field": "kubernetes.event.timestamp.first_occurrence"
                        },
                        "meta": {
                          "bounds": 1621929905725
                        }
                      }
                    }
                  },

This is how you can use it somewhere in your vega spec, e.g. to specify the domain of an axis:

scale: {
        domain: [
          {expr: "data('data_0')[0].start.time.meta.bounds"},
          {expr: "data('data_0')[0].end.time.meta.bounds"}
        ]
      }


1 Like