# Sorting based on a script calculated field value

Hi Kimchy,

We want to introduce a feature to our product, I am interested to know if
Scripting could do anything in this. We have a field which has a numeric
value. I believe we can do math operations on a field using script. I would
like to know, if it is possible to sort the hits based on the calculated
script value?

Manoj

On Mon, 2012-05-28 at 06:24 -0700, Manoj wrote:

Hi Kimchy,

We want to introduce a feature to our product, I am interested to know
if Scripting could do anything in this. We have a field which has a
numeric value. I believe we can do math operations on a field using
script. I would like to know, if it is possible to sort the hits based
on the calculated script value?

yes it is.

clint

Manoj

Thanks for directing me to the link Clinton,

Is this too possible in scripting,

I have a score value, and an Id for every hit. I need to find the number
of hits we get for every id (similar to faceting the particular id) and
then multiply the score of every article with the count (number of hits
with the id) of the id. And then, applying sort on the final calculated
value

To be more clear, I have tried to explain with a sample data below

Score id number_of_articles_with_the_id finalvalue
5 1234 9
9*5=45

I am interested to know if the above criteria could be achieved in a single
call to the index?

On Monday, May 28, 2012 9:47:16 PM UTC+5:30, Clinton Gormley wrote:

On Mon, 2012-05-28 at 06:24 -0700, Manoj wrote:

Hi Kimchy,

We want to introduce a feature to our product, I am interested to know
if Scripting could do anything in this. We have a field which has a
numeric value. I believe we can do math operations on a field using
script. I would like to know, if it is possible to sort the hits based
on the calculated script value?

yes it is.

Elasticsearch Platform — Find real-time answers at scale | Elastic

clint

Manoj

On Tuesday, May 29, 2012 10:32:27 AM UTC+5:30, Manoj wrote:

Thanks for directing me to the link Clinton,

Is this too possible in scripting,

I have a score value, and an Id for every hit. I need to find the number
of hits we get for every id (similar to faceting the particular id) and
then multiply the score of every article with the count (number of hits
with the id) of the id. And then, applying sort on the final calculated
value

To be more clear, I have tried to explain with a sample data below

Score id number_of_articles_with_the_id finalvalue
5 1234 9
9*5=45

I am interested to know if the above criteria could be achieved in a
single call to the index?

On Monday, May 28, 2012 9:47:16 PM UTC+5:30, Clinton Gormley wrote:

On Mon, 2012-05-28 at 06:24 -0700, Manoj wrote:

Hi Kimchy,

We want to introduce a feature to our product, I am interested to know
if Scripting could do anything in this. We have a field which has a
numeric value. I believe we can do math operations on a field using
script. I would like to know, if it is possible to sort the hits based
on the calculated script value?

yes it is.