# Use Elastic GET script output in Lens (or TSVB) panel

**URL:** <https://discuss.elastic.co/t/use-elastic-get-script-output-in-lens-or-tsvb-panel/326349>\
**Category:** Kibana\
**Tags:** lens\
**Created:** [February 23, 2023, 4:31pm UTC](https://discuss.elastic.co/t/use-elastic-get-script-output-in-lens-or-tsvb-panel/326349 "2023-02-23T16:31:58Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![ivh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ivh/32/87876_2.png) [@ivh](https://discuss.elastic.co/u/ivh)\
**Post date:** [February 23, 2023, 4:31pm UTC](https://discuss.elastic.co/t/use-elastic-get-script-output-in-lens-or-tsvb-panel/326349/1 "2023-02-23T16:31:58Z")

</div>

Hello! Tried solving this via an Elastic Support case, got nowhere ... hoping the community can help.

I have a working GET script that successfully retrieves a single document (from an entire index) that contains the max value of a numeric field (in this case, a daily closing price for a mutual fund). See script and response below.

Now I want to plot that value ( **50.86** ) as a static horizontal line in a Lens panel (or in TSVB) -- such that the value never changes, **regardless of the time range selected by the user**.

Can anyone show me how to use the Lens UI to accomplish this based on my (working) script? I assume I should use a "formula" -- but I can't find any posts, videos, screengrabs, etc. anywhere that depict _how._

Thanks!

[snip]

Particulars...

- **Index:** `wxmd`
- **X-Axis/Time Field:** `last_update`
- **Field:** `price_close`
- **Term:** `symbol` (target value: `dodfx`)

Script...

```auto
GET /wxmd/_search?pretty
{
    "query": { "bool": { "filter": [{ "term": { "symbol": "dodfx" } }] } },
    "size": 0,
    "aggs":{ "max_price_close": { "top_hits": { "sort": [{ "price_close": { "order": "desc" } }], "size": 1 } } }
}

```

Response...

```auto
{
    "took": 1,
    "timed_out": false,
    "_shards": {
        "total": 1,
        "successful": 1,
        "skipped": 0,
        "failed": 0
    },
    "hits": {
        "total": {
            "value": 1080,
            "relation": "eq"
        },
        "max_score": null,
        "hits": []
    },
    "aggregations": {
        "max_price_close": {
            "hits": {
                "total": {
                    "value": 1080,
                    "relation": "eq"
                },
                "max_score": null,
                "hits": [
                    {
                        "_index": "wxmd",
                        "_type": "_doc",
                        "_id": "VGJc8nkBH0ZppaLYUYbw",
                        "_score": null,
                        "_source": {
                            "price_close": "50.86",
                            "volume": "0",
                            "last_update": "2021-06-08 13:00",
                            "symbol": "DODFX"
                        },
                        "sort": [
                            50.86
                        ]
                    }
                ]
            }
        }
    }
}

```

---

<div class="post-metadata">

**Author:** ![BenB196](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/benb196/32/83401_2.png) [@BenB196](https://discuss.elastic.co/u/BenB196)\
**Post date:** [February 23, 2023, 4:40pm UTC](https://discuss.elastic.co/t/use-elastic-get-script-output-in-lens-or-tsvb-panel/326349/2 "2023-02-23T16:40:49Z")

</div>

I'm going to give you only a partial answer as I'm not too familiar with the subject.

1. I don't think this is possible to do in either Lens or TSVB, I think in both cases, they limit annotations based on queries to exists fields and time ranges.
2. You might be able to do this via the Vega visualization.
  - This is where I can't provide much help, but Vega does allow you to add annotations via queries; [Mean overlay over precipitation chart | Vega-Lite](https://vega.github.io/vega-lite/examples/layer_precipitation_mean.html). Given that the Vega visualization has much more flexibility you _might_ be able to achieve your desired outcome here.
  - [Download Kibana visualization examples at elastic content share](https://elastic-content-share.eu/downloads/category/kibana/kibana-visualizations/) has some good examples of using the Vega visualization which might help get you started in this direction.

---

<div class="post-metadata">

**Author:** ![Marco\_Liberati](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marco_liberati/32/82953_2.png) [@Marco\_Liberati](https://discuss.elastic.co/u/Marco_Liberati)\
**Post date:** [February 23, 2023, 4:51pm UTC](https://discuss.elastic.co/t/use-elastic-get-script-output-in-lens-or-tsvb-panel/326349/3 "2023-02-23T16:51:58Z")

</div>

Hi @ivh

have you checked Reference Lines in Lens?  
You can do your chart, then add a new layer of type `Reference line` and add one static or computed line:

 ![Screenshot 2023-02-23 at 17.51.08](https://us1.discourse-cdn.com/elastic/original/3X/4/8/48285d452800b97154e8e816a41d4e02e757270f.png)

---

<div class="post-metadata">

**Author:** ![ivh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ivh/32/87876_2.png) [@ivh](https://discuss.elastic.co/u/ivh)\
**Post date:** [February 23, 2023, 6:48pm UTC](https://discuss.elastic.co/t/use-elastic-get-script-output-in-lens-or-tsvb-panel/326349/4 "2023-02-23T18:48:19Z")

</div>

Thanks @BenB196 -- appreciate the quick reply & the tip. Will LYK if that does it.

---

<div class="post-metadata">

**Author:** ![ivh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ivh/32/87876_2.png) [@ivh](https://discuss.elastic.co/u/ivh)\
**Post date:** [February 23, 2023, 7:43pm UTC](https://discuss.elastic.co/t/use-elastic-get-script-output-in-lens-or-tsvb-panel/326349/5 "2023-02-23T19:43:28Z")

</div>

![Screenshot 2023-02-23 at 10.48.54 AM](https://us1.discourse-cdn.com/elastic/original/3X/4/4/4421b669ad9caffe1d72920f1b22220e847bcfff.png)

I have used reference line w/ static value -- see attached.

It's the "computed" option I'm struggling with 😀

---

<div class="post-metadata">

**Author:** ![Marco\_Liberati](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marco_liberati/32/82953_2.png) [@Marco\_Liberati](https://discuss.elastic.co/u/Marco_Liberati)\
**Post date:** [February 24, 2023, 8:37am UTC](https://discuss.elastic.co/t/use-elastic-get-script-output-in-lens-or-tsvb-panel/326349/6 "2023-02-24T08:37:50Z")

</div>

Why not using a `Last value` as in my screenshot for the reference line?

---

<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:** [March 24, 2023, 8:38am UTC](https://discuss.elastic.co/t/use-elastic-get-script-output-in-lens-or-tsvb-panel/326349/7 "2023-03-24T08:38:07Z")

</div>

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