I'm using elastic search and I would like to sort documents having same score to the query shown below, on the basis of higher number of - "likes" field - integer type stored in all documents. Code -
query: {
multi_match: {
query: "some cooler",
type: "most_fields",
fields: ["info1", "info2", "info3"]
}
}
You should check the sort documentation
Just add a sort section on json sorting by score followed by your custom field.
{
"query" : {...},
"sort" : [
"_score",
{ "likes" : {"order" : "desc"}}
]
}
score order is 'desc' by default. Other fields are 'asc' by default so you need to define 'desc' order for your 'likes' field if that's what you want.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With