# Using ctx.results Variable in a Message

**URL:** <https://discuss.elastic.co/t/using-ctx-results-variable-in-a-message/216498>\
**Category:** Kibana\
**Tags:** painless\
**Created:** [January 24, 2020, 10:45pm UTC](https://discuss.elastic.co/t/using-ctx-results-variable-in-a-message/216498 "2020-01-24T22:45:56Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![stevebanik](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stevebanik/32/100001_2.png) [@stevebanik](https://discuss.elastic.co/u/stevebanik)\
**Post date:** [January 24, 2020, 10:45pm UTC](https://discuss.elastic.co/t/using-ctx-results-variable-in-a-message/216498/1 "2020-01-24T22:45:56Z")

</div>

I'd like to use the `ctx.results` variable in a message using `{{ctx.results.0}}` but I am not able to display the \_source value I'm interested in.

For example, the extraction query response is:

```
{
    "_shards": {
        "total": 123,
        "failed": 0,
        "successful": 123,
        "skipped": 0
    },
    "hits": {
        "hits": [
            {
                "_index": "winlogbeat-6.8.6-2019.12.26",
                "_type": "_doc",
                "_source": {
                    "process_id": 4,
                    "computer_name": "machine1.foo.com",
                    "keywords": [
                        "Audit Success"
                    ],

```

and I would like to print the `computer_name` value in the message body. I tried `{{ctx.results.0._source.computer_name.value}}` and various other combinations, but none worked. Do you have any advice?

Thanks,  
Steve

---

<div class="post-metadata">

**Author:** ![Marius\_Dragomir](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marius_dragomir/32/42087_2.png) [@Marius\_Dragomir](https://discuss.elastic.co/u/Marius_Dragomir)\
**Post date:** [January 29, 2020, 10:31am UTC](https://discuss.elastic.co/t/using-ctx-results-variable-in-a-message/216498/2 "2020-01-29T10:31:57Z")

</div>

You can use this as a guide: [Cannot figure out how to get data from \_source into Watch Output](https://discuss.elastic.co/t/cannot-figure-out-how-to-get-data-from--source-into-watch-output/86446/7)

---

<div class="post-metadata">

**Author:** ![stevebanik](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stevebanik/32/100001_2.png) [@stevebanik](https://discuss.elastic.co/u/stevebanik)\
**Post date:** [February 7, 2020, 6:53pm UTC](https://discuss.elastic.co/t/using-ctx-results-variable-in-a-message/216498/3 "2020-02-07T18:53:59Z")

</div>

My problem was that I was (incorrectly) attempting to reference the entire array, rather than an element in the array. Once I referenced the element, the issue was resolved.

---

<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 6, 2020, 6:54pm UTC](https://discuss.elastic.co/t/using-ctx-results-variable-in-a-message/216498/4 "2020-03-06T18:54:03Z")

</div>

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