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

Hi, I'm actually working with vega in kibana, and I need to access to the two borns of date filter of kibana, In fact I've succeeded to limit the data processed to the range by specifying the "%timefield", but I also need the min and max of the inteval setted on kibana to make some personalized computations

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

Thanks for your reply, I've followed the steps you described, I've been able to see the date ranges in the inspect panel, but I can't retrieve their values from a painless script, I've searched a lit a bit in the doc but I haven't found something useful, do you have some idea on how to achieve this ?
This is a screenshot of what I'm trying to do

In that case I misunderstood you - I thought you wanted to use the time range in the vega spec, but you actually want to use it as part of the Elasticsearch request in a scripted metric.

I'm not sure where you try to get to with your script. Please post in the Elasticsearch forum instead Elasticsearch - Discuss the Elastic Stack and explain what exactly you want to calculate using your scripted metric.

For the vega part (passing the bounds into the script) - see the params parameter of the scripted metric: Scripted metric aggregation | Elasticsearch Guide [7.13] | Elastic

You should be able to put the vega placeholder %timefilter%: min in there and it will be resolved and available as a variable in your scripts.

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