# Is there any way elasticsearch ranges key can be converted with scripted values

**URL:** <https://discuss.elastic.co/t/is-there-any-way-elasticsearch-ranges-key-can-be-converted-with-scripted-values/74465>\
**Category:** Elasticsearch\
**Created:** [February 9, 2017, 7:15am UTC](https://discuss.elastic.co/t/is-there-any-way-elasticsearch-ranges-key-can-be-converted-with-scripted-values/74465 "2017-02-09T07:15:04Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shashi-GS](https://avatars.discourse-cdn.com/v4/letter/s/13edae/32.png) [@Shashi-GS](https://discuss.elastic.co/u/Shashi-GS)\
**Post date:** [February 9, 2017, 7:15am UTC](https://discuss.elastic.co/t/is-there-any-way-elasticsearch-ranges-key-can-be-converted-with-scripted-values/74465/1 "2017-02-09T07:15:04Z")

</div>

Is there any way elasticsearch ranges key can be converted with scripted values ?  
Could some one help me can I achieve similar kind of query from elasticsearch ?

I am trying to do the bucketing with dynamic field values.

```
{
    "size": 0,
    "_source": false,
    "query": {
        "filtered": {
            "filter": {
                "bool": {
                    "must": {
                        "match_all": {
                            
                        }
                    }
                }
            }
        }
    },
    "aggs": {
        "financialyear": {
            "range": {
                "ranges": [
                    {
                        "key": {
                            "script": "doc['__year_salesDate'].value - 1"
                            
                        },
                        "from": "1",
"to": "3"
                    },
                    {
                        "key": {
                            "script": "doc['__year_salesDate'].value"
                            
                        },
                        "from": "4",
"to": "12"
                    }
                ],
                "field": "__month_salesDate"
            }
        }
    }
}
}
```

---

<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:** [March 9, 2017, 7:15am UTC](https://discuss.elastic.co/t/is-there-any-way-elasticsearch-ranges-key-can-be-converted-with-scripted-values/74465/2 "2017-03-09T07:15:11Z")

</div>

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