# Accessing context in script for ranges

**URL:** <https://discuss.elastic.co/t/accessing-context-in-script-for-ranges/20515>\
**Category:** Elasticsearch\
**Created:** [October 31, 2014, 1:05pm UTC](https://discuss.elastic.co/t/accessing-context-in-script-for-ranges/20515 "2014-10-31T13:05:19Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael\_Gallego](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/michael_gallego/32/933_2.png) [@Michael\_Gallego](https://discuss.elastic.co/u/Michael_Gallego)\
**Post date:** [October 31, 2014, 1:05pm UTC](https://discuss.elastic.co/t/accessing-context-in-script-for-ranges/20515/1 "2014-10-31T13:05:19Z")

</div>

Hi,

Let's say I'm doing the following date ranges aggregation:

{  
"aggs": {  
"foo": {  
"date\_range": {  
"script": "??",  
"ranges": [  
{"from": "2014-01-01", "to": "2014-02-01"},  
{"from": "2014-02-01", "to": "2014-03-01"}  
]  
}  
}  
}  
}

Is there any way I can get access to the range context inside the script?  
In this case, I'd like to be able to have access to the "from" or "to"  
values, when the range is executed. I've tried to use "from", "ctx.from",  
"context.from", but it does not seem to work :(.

Thanks

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/5021b5a1-78fe-4d7c-bc43-d7c653381f19%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/5021b5a1-78fe-4d7c-bc43-d7c653381f19%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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 6, 2017, 12:52am UTC](https://discuss.elastic.co/t/accessing-context-in-script-for-ranges/20515/2 "2017-07-06T00:52:49Z")

</div>

Closed on July 6, 2017, 12:52am UTC


