Sort part of the documents by date difference

Hi,

I was wondering how would you guys solve this one:

  • I have an index with 3 different document types
  • One of those document type contains datetime spanning from past to future dates
  • When user searches we display results from all document types at once

For this specific documents which have a datetime property I would like to rank higher documents that are closer to the current date (now), but without impacting the order of other documents without datetime.

For example if we have NBA games, teams and players ... only games will have a match date. When user types Toronto .... we return a list of results where you have Toronto Raprots, John Toronto, and then a list of games... but among those games we arrange them so the ones closer to today are higher.

But if there is another team or player among those games that are being sorted we don't change their position in the returned list.

Hope you understand what I try to achieve.
Thanks for any answers.

I solved this one using decay functions.
https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html#function-decay

1 Like

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