Multiply the field in query result and sort


#1

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!


(system) #2

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