# Multiply the field in query result and sort

**URL:** <https://discuss.elastic.co/t/multiply-the-field-in-query-result-and-sort/83695>\
**Category:** Elasticsearch\
**Created:** [April 26, 2017, 12:15pm UTC](https://discuss.elastic.co/t/multiply-the-field-in-query-result-and-sort/83695 "2017-04-26T12:15:31Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![hassahma](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hassahma/32/17696_2.png) [@hassahma](https://discuss.elastic.co/u/hassahma)\
**Post date:** [April 26, 2017, 12:15pm UTC](https://discuss.elastic.co/t/multiply-the-field-in-query-result-and-sort/83695/1 "2017-04-26T12:15:31Z")

</div>

I am using elasticsearch 2.4 with java transport client. I want to fetch results of a 'field1' after multiplying it with value '0.3', sort it and then fetch first 10 results. I do the following but the multiplication doesn't happen. I rather see the original values of field1.

SearchResponse response = client.prepareSearch(index)  
.setSearchType(SearchType.DFS\_QUERY\_THEN\_FETCH)  
.setQuery(QueryBuilders.matchAllQuery()) // Query  
.setQuery(QueryBuilders.scriptQuery(new Script("doc['field1'].value \* 0.3", ScriptType.INLINE, "groovy", null)))  
.setPostFilter(QueryBuilders.rangeQuery("time").from("now-3d")) // Filter  
.addSort("field1", SortOrder.DESC)  
.setFrom(0).setSize(10)  
.setExplain(true)  
.execute()  
.actionGet();

Thanks for the help!

---

<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:** [May 24, 2017, 12:18pm UTC](https://discuss.elastic.co/t/multiply-the-field-in-query-result-and-sort/83695/2 "2017-05-24T12:18:23Z")

</div>

Closed on May 24, 2017, 12:18pm UTC

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