Sorting based on a certain field being true

I am currently on ES V 2.3, and would like to sort on all the records based on a specific value being true.

the record may contain the following object:

"pinning": {
    "from": "2017-10-16T16:34:00Z",
    "order": 0,
    "pinned": false,
    "until": "2018-11-30T16:34:00Z"
},

my current sort is the following:

"sort": [
      {
         "pinning.order": {
            "order": "asc"
         }
      },
      {
      "_score": {
        "order": "desc"
        }
  },

Almost all records are sorted based on score, and score is based off of date.

The pinning.pinned field boosts the score significantly.

The reason for pinning.order is so that even if the record is pinned at an earlier date, but it is set to a lower order than a previously pinned card, it wouldn't be returned higher in the order by ES.

That is why pinning.order is higher on the sorting priority list than _score otherwise a card with lower priority may be returned higher because of the score being higher due to date being earlier.

When pinning.pinned is set to false, my function scoring does not take into effect (which is intended) and the score of the record is not boosted where as any record with pinning.pinned = true the score is boosted significantly

The problem is that even if pinning.pinned is set to false, the record is sorted based on pinning.order which still exists in the object

Is there a way to sort the record based on pinning.order ONLY if pinning.pinning = true, otherwise sort it based on _score?

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.