# Creating a dynamic scripted field

**URL:** https://discuss.elastic.co/t/creating-a-dynamic-scripted-field/58108
**Category:** Elasticsearch
**Created:** [August 16, 2016, 7:43am UTC](https://discuss.elastic.co/t/creating-a-dynamic-scripted-field/58108 "2016-08-16T07:43:55Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![gilisade](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gilisade/32/98740_2.png) [@gilisade](https://discuss.elastic.co/u/gilisade)
#### Post date: [August 16, 2016, 7:43am UTC](https://discuss.elastic.co/t/creating-a-dynamic-scripted-field/58108/1 "2016-08-16T07:43:55Z")

</div>

hi there  
i'm trying to get the latest value of a certain field into a scripted field  
what i did is this  
GET INDEX\_NAME/\_search  
{  
"query": {"term": {  
"type": {  
"value": "certain\_type"  
}  
}  
} ,  
"fields": ["@timestamp" , "sum\_users"],

"size": 1 ,  
"sort": [  
{  
"@timestamp": {  
"order": "desc"  
}  
}  
] ,  
"script\_fields": {  
"last\_value": {  
"script": "doc['sum\_users'].value"  
}  
}  
}

what i got here is the latest value of the field "sum\_users" filtered by a certain type into a scripted field called "latest vlaue"  
now i want this to become a single dynamic field that means that i want tihs script to run every few min or so , that the value of "latest value" will change acordingly - even making it like a unique document that changes over time acordingly

can anyone help me on that , how to create that scripted "document" in a certain index

thank you!

---

<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, 10:27pm UTC](https://discuss.elastic.co/t/creating-a-dynamic-scripted-field/58108/2 "2017-07-05T22:27:35Z")

</div>


