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

**URL:** <https://discuss.elastic.co/t/is-it-possible-to-get-the-timefield-value-on-vega-script/276191>\
**Category:** Kibana\
**Tags:** vega\
**Created:** [June 16, 2021, 7:57pm UTC](https://discuss.elastic.co/t/is-it-possible-to-get-the-timefield-value-on-vega-script/276191 "2021-06-16T19:57:52Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ayanam](https://avatars.discourse-cdn.com/v4/letter/a/b9bd4f/32.png) [@ayanam](https://discuss.elastic.co/u/ayanam)\
**Post date:** [June 16, 2021, 7:57pm UTC](https://discuss.elastic.co/t/is-it-possible-to-get-the-timefield-value-on-vega-script/276191/1 "2021-06-16T19:57:52Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![flash1293](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/flash1293/32/41227_2.png) [@flash1293](https://discuss.elastic.co/u/flash1293)\
**Post date:** [June 17, 2021, 12:35pm UTC](https://discuss.elastic.co/t/is-it-possible-to-get-the-timefield-value-on-vega-script/276191/2 "2021-06-17T12:35:13Z")

</div>

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

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

```

Elasticsearch will reflect the meta information in the response:

```auto
"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:

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

```

---

<div class="post-metadata">

**Author:** ![ayanam](https://avatars.discourse-cdn.com/v4/letter/a/b9bd4f/32.png) [@ayanam](https://discuss.elastic.co/u/ayanam)\
**Post date:** [June 21, 2021, 8:38am UTC](https://discuss.elastic.co/t/is-it-possible-to-get-the-timefield-value-on-vega-script/276191/3 "2021-06-21T08:38:33Z")

</div>

> [@flash1293](#):
>
> `data('data_0')[0].end.time.meta.bounds`

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

 ![painless_vega_bounds](https://us1.discourse-cdn.com/elastic/original/3X/c/1/c131747f64b99d3bfc87491484f7147ec503b179.png)

---

<div class="post-metadata">

**Author:** ![flash1293](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/flash1293/32/41227_2.png) [@flash1293](https://discuss.elastic.co/u/flash1293)\
**Post date:** [June 21, 2021, 9:52am UTC](https://discuss.elastic.co/t/is-it-possible-to-get-the-timefield-value-on-vega-script/276191/4 "2021-06-21T09:52:40Z")

</div>

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](https://discuss.elastic.co/c/elastic-stack/elasticsearch/6) 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](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-scripted-metric-aggregation.html#scripted-metric-aggregation-parameters)

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.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 19, 2021, 9:53am UTC](https://discuss.elastic.co/t/is-it-possible-to-get-the-timefield-value-on-vega-script/276191/5 "2021-07-19T09:53:26Z")

</div>

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