How can I sort by a calculated value in elasticsearch How can I sort by a calculated value in elasticsearch elasticsearch elasticsearch

How can I sort by a calculated value in elasticsearch


The same as with filtering. Take a look at this section of the documentation. It should be self-explanatory once you already know about scripts :-).

For the completeness sake:

{    "query" : {        ....    },    "sort" : {        "_script" : {            "type" : "number",            "script" : {                "inline": "doc['field_name'].value * factor",                "params" : {                    "factor" : 1.1                }            },            "order" : "asc"        }    }}