# Rewrite query without dynamic scipting

**URL:** <https://discuss.elastic.co/t/rewrite-query-without-dynamic-scipting/60302>\
**Category:** Elasticsearch\
**Created:** [September 12, 2016, 2:23pm UTC](https://discuss.elastic.co/t/rewrite-query-without-dynamic-scipting/60302 "2016-09-12T14:23:31Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pintac](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pintac/32/10311_2.png) [@Pintac](https://discuss.elastic.co/u/Pintac)\
**Post date:** [September 12, 2016, 2:23pm UTC](https://discuss.elastic.co/t/rewrite-query-without-dynamic-scipting/60302/1 "2016-09-12T14:23:31Z")

</div>

Hi

i have a old query that does a fuzzy query on a field and then does a term aggregate on that field and then a sub aggregation on max \_score.

I am moving over to elastic cloud but i can't use the query becuase elastic cloud does not have fine grain control of dynamic scripting permitions.

So how do rewrite this query without needing dynamic scripting permission.

> {  
> "size": 0,  
> "query": {  
> "match": {  
> "basic.province": "ga"  
> }  
> },  
> "aggs": {  
> "term\_agg": {  
> "terms": {  
> "field": "basic.province.untouched",  
> "size": 10,  
> "order": {  
> "max\_score": "desc"  
> }  
> },  
> "aggs": {  
> "max\_score": {  
> "max": {  
> "script": "\_score"  
> }  
> }  
> }  
> }  
> }  
> }

thanks

---

<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:21pm UTC](https://discuss.elastic.co/t/rewrite-query-without-dynamic-scipting/60302/2 "2017-07-05T22:21:03Z")

</div>

Closed on July 5, 2017, 10:21pm UTC


