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?

Thanks in advance!
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.

See script based sorting on this page:

clint

Thanks in advance!
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.

See script based sorting on this page:
Elasticsearch Platform — Find real-time answers at scale | Elastic

clint

Thanks in advance!
Manoj

Everyone, any update about this!

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.

See script based sorting on this page:
Elasticsearch Platform — Find real-time answers at scale | Elastic

clint

Thanks in advance!
Manoj

This is exactly what I want to do ... any update how you solved it?