# How to reference a script field value in another script

**URL:** https://discuss.elastic.co/t/how-to-reference-a-script-field-value-in-another-script/37905
**Category:** Elasticsearch
**Created:** [December 24, 2015, 3:54am UTC](https://discuss.elastic.co/t/how-to-reference-a-script-field-value-in-another-script/37905 "2015-12-24T03:54:36Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![zaza](https://avatars.discourse-cdn.com/v4/letter/z/e19b73/32.png) [@zaza](https://discuss.elastic.co/u/zaza)
#### Post date: [December 24, 2015, 3:54am UTC](https://discuss.elastic.co/t/how-to-reference-a-script-field-value-in-another-script/37905/1 "2015-12-24T03:54:36Z")

</div>

I calculate a script field (a little performance-expensive) when search, an then I want to reference the script field value in a script sort. I seems elasticsearch not support it now, I can only reference the doc field value in a script sort.

Or I want to reference the script field value in a script\_score script, then at the sorting phase I just use the \_score value. But It seems I cant reference the script field value in a script\_score script too.

Is there some advice to achieve it?

---

<div class="post-metadata">

### Author: ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)
#### Post date: [December 24, 2015, 5:46am UTC](https://discuss.elastic.co/t/how-to-reference-a-script-field-value-in-another-script/37905/2 "2015-12-24T05:46:26Z")

</div>

You can't do this unfortunately.

Can you take the results of script 1 and create a new field with it? Then you could reference it.

---

<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 5, 2017, 11:28pm UTC](https://discuss.elastic.co/t/how-to-reference-a-script-field-value-in-another-script/37905/3 "2017-07-05T23:28:56Z")

</div>


