Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sorting by multiple params in pyes and elasticsearch

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

like image 500
AnalyticsBuilder Avatar asked Jan 31 '12 17:01

AnalyticsBuilder


People also ask

How do you sort an array in Elasticsearch?

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.

What is the default sort order for relevance score in Elasticsearch?

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.

How to sort Dataframe using pyspark?

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

What is the sort parameter in SQL Server?

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.


1 Answers

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')
like image 128
AnalyticsBuilder Avatar answered Sep 20 '22 15:09

AnalyticsBuilder