# Using \`ctx\` to access source field

**URL:** <https://discuss.elastic.co/t/using-ctx-to-access-source-field/115129>\
**Category:** Elasticsearch\
**Created:** [January 11, 2018, 3:58pm UTC](https://discuss.elastic.co/t/using-ctx-to-access-source-field/115129 "2018-01-11T15:58:44Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![arisbanach](https://avatars.discourse-cdn.com/v4/letter/a/f07891/32.png) [@arisbanach](https://discuss.elastic.co/u/arisbanach)\
**Post date:** [January 11, 2018, 3:58pm UTC](https://discuss.elastic.co/t/using-ctx-to-access-source-field/115129/1 "2018-01-11T15:58:44Z")

</div>

What does `ctx` stand for? I can't find it in the docs.

---

<div class="post-metadata">

**Author:** ![val](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/val/32/138203_2.png) [@val](https://discuss.elastic.co/u/val)\
**Post date:** [January 11, 2018, 4:01pm UTC](https://discuss.elastic.co/t/using-ctx-to-access-source-field/115129/2 "2018-01-11T16:01:28Z")

</div>

Depends on the context. Care to tell more?

Here are some uses of the `ctx` variable:  
[https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-scripting-fields.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-scripting-fields.html)

---

<div class="post-metadata">

**Author:** ![arisbanach](https://avatars.discourse-cdn.com/v4/letter/a/f07891/32.png) [@arisbanach](https://discuss.elastic.co/u/arisbanach)\
**Post date:** [January 11, 2018, 4:06pm UTC](https://discuss.elastic.co/t/using-ctx-to-access-source-field/115129/3 "2018-01-11T16:06:05Z")

</div>

I'm just more curious about the name of the variable itself, regardless of use context. Does `ctx` stand for something? "Something transaction"? Why choose the letters `ctx`?

---

<div class="post-metadata">

**Author:** ![arisbanach](https://avatars.discourse-cdn.com/v4/letter/a/f07891/32.png) [@arisbanach](https://discuss.elastic.co/u/arisbanach)\
**Post date:** [January 11, 2018, 4:06pm UTC](https://discuss.elastic.co/t/using-ctx-to-access-source-field/115129/4 "2018-01-11T16:06:21Z")

</div>

Oh wait... context... right?

---

<div class="post-metadata">

**Author:** ![val](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/val/32/138203_2.png) [@val](https://discuss.elastic.co/u/val)\
**Post date:** [January 11, 2018, 4:07pm UTC](https://discuss.elastic.co/t/using-ctx-to-access-source-field/115129/5 "2018-01-11T16:07:26Z")

</div>

yes, `ctx` provides "context" for your scripts

---

<div class="post-metadata">

**Author:** ![arisbanach](https://avatars.discourse-cdn.com/v4/letter/a/f07891/32.png) [@arisbanach](https://discuss.elastic.co/u/arisbanach)\
**Post date:** [January 11, 2018, 5:05pm UTC](https://discuss.elastic.co/t/using-ctx-to-access-source-field/115129/6 "2018-01-11T17:05:13Z")

</div>

So I'm still somewhat unclear on its need though. Context is just what the values of the document are, right? Wouldn't that be the same as just accessing the `doc` values?

---

<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:** [February 8, 2018, 5:05pm UTC](https://discuss.elastic.co/t/using-ctx-to-access-source-field/115129/7 "2018-02-08T17:05:31Z")

</div>

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