0

I have a tutors index in elastic search. I have stored all tutors data there. I want to make tie breaker query if two doc has same score in elasticsearch. Like if two tutor has same score then i want to display the tutor first which has more teaching hours, if that are also same then i want to display the tutor first which was registered first.

My index data is like below :

{
"_index": "tutors",
"_type": "tutors",
"_id": "1",
"_score": 1.2308,
"_source": {
    "first_name": "Alessia",
    "last_name": "Williams",
    "slug": "alessia",
    "verified": 1,
    "approved": 1,
    "total_teaching_hours": 105,
    "registered_at": "2022-01-14T07:36:48.000000Z",
    }
},
{
"_index": "tutors",
"_type": "tutors",
"_id": "2",
"_score": 1.2308,
"_source": {
    "first_name": "Anika",
    "last_name": "Rivera",
    "slug": "anika",
    "verified": 1,
    "approved": 1,
    "total_teaching_hours": 104,
    "registered_at": "2022-02-14T07:36:48.000000Z",
    }
},
{
"_index": "tutors",
"_type": "tutors",
"_id": "3",
"_score": 1.2308,
"_source": {
    "first_name": "Anika",
    "last_name": "Rivera",
    "slug": "anika",
    "verified": 1,
    "approved": 1,
    "total_teaching_hours": 105,
    "registered_at": "2022-02-14T07:36:48.000000Z",
    }
}
James Z
  • 12,209
  • 10
  • 24
  • 44
Kajal Pandya
  • 75
  • 1
  • 7

1 Answers1

0

Please have a look at the documentation here.

The query will go something like this:

{
    "query": {....},
    "sort": [
        "_score",
        {
            "total_teaching_hours": {
                "order": desc
             }
        },
        {
           "registered_at": {
               "order": asc
           }
        }
    ]
}