I can pass a single sort parameter to the search query in pyes like this:
s = MatchAllQuery()
conn.search(query=Search(s), indexes=["test"], sort='_score')
But I need to pass an extra parameter to sort the docs with the same score, like this:
{
"sort": [
"_score",
{
"extra_param": {
"order": "asc"
}
}
],
"query": {
"term": {
"match_all": {}
}
}
}
How can I do this in pyes?
Thanks
Elasticsearch Sorting. In its simplest form, an object in the sort array is an object with a single property whose name matches the field to sort by and whose value is the order by which to sort, “asc” for ascending or “desc” for descending.
In Elasticsearch, the relevance score is represented by the floating-point number returned in the search results as the _score, so the default sort order is _score descending. In the previous example, we searched for movies from 1962.
Method 1: Using sort () function 1 dataframe is the dataframe name created from the nested lists using pyspark 2 where columns are the llst of columns 3 ascending = True specifies order the dataframe in increasing order, ascending=False specifies order the dataframe in decreasing order
This is where the sort parameter comes in handy, allowing us to sort results by one or more fields. As an example, we can take our previous query and sort the results explicitly by the venue_name in ascending order. It’s that simple. Or at least it should be in principle.
If you'd like the results in the result set with the same score to be ordered by price, append price to the sort string:
s = MatchAllQuery()
conn.search(query=Search(s), indexes=["test"], sort='_score,price')
By default the sort order is ascending. To pass the sort order append :asc or :desc to the sort parameter
s = MatchAllQuery()
conn.search(query=Search(s), indexes=["test"], sort='_score,price:desc')
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