# Provide values to the ctx.vars variables in the Painless file by extracting them from the YAML file

**URL:** <https://discuss.elastic.co/t/provide-values-to-the-ctx-vars-variables-in-the-painless-file-by-extracting-them-from-the-yaml-file/338172>\
**Category:** Elasticsearch\
**Tags:** painless\
**Created:** [July 12, 2023, 5:37am UTC](https://discuss.elastic.co/t/provide-values-to-the-ctx-vars-variables-in-the-painless-file-by-extracting-them-from-the-yaml-file/338172 "2023-07-12T05:37:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hardik\_Dave](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hardik_dave/32/123316_2.png) [@Hardik\_Dave](https://discuss.elastic.co/u/Hardik_Dave)\
**Post date:** [July 12, 2023, 5:37am UTC](https://discuss.elastic.co/t/provide-values-to-the-ctx-vars-variables-in-the-painless-file-by-extracting-them-from-the-yaml-file/338172/1 "2023-07-12T05:37:24Z")

</div>

I have a .painless file as mentioned below. As of now, the ctx.vars.var1 have hardcoded values in my original file, which now need to be retrieved from a YAML file. All these files are in same project, so relative path will not be an issue.

```auto
if(ctx.metadata.Env == 'dev1' || ctx.metadata.Env == 'qa9' {
    ctx.vars.var1 = 'get this value from a YAML file';
    ctx.vars.var2 = 'get this value from a YAML file';
}

```

An example of YAML file and its content as below. The file name can be SomeFile.yaml, which resides in the same solution.

```auto
- name: Key1 
     value: Value1
- name: Key2 
     value: Value2

```

I need assistance how to extract the values from the YAML file and place them into those ctx.vars.var1 and var2 variables. Any help will be appreciated as I need to incorporate in my project.

---

<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:** [August 9, 2023, 5:37am UTC](https://discuss.elastic.co/t/provide-values-to-the-ctx-vars-variables-in-the-painless-file-by-extracting-them-from-the-yaml-file/338172/2 "2023-08-09T05:37:45Z")

</div>

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