A question about sort order query in elasticsearch

Hi,I have a problem on sorting order in elasticsearch.
When i use elasticsearch to do full-text search,i use text's score as the first order in descending and use update time field as the second order in descending.

I want to get the latest data in search result order by similarity in descending and when the search result have same similarity,the data can order by updatetime in descending .

But i am not lucky,the data i get was not what i want,actually,those data in search result was very old even though they have a high similarity with my inputs.

I want to get the latest data ,the search data can order by similarity in descending,and if they have same similarity,they can order by update time in descending.

Could anybody please help me? I am so lucky if anybody can give me a complete demo or some ideas about this.I use the Nest client,the version of it is 2.2.
Thank you !

Hi @smile-sunsshine,

if you strictly only want recent data, you need to filter for the range in which you are searching (e.g. range query on the time field). Then you can sort by similarity, and tie break on the update time for example. Otherwise some old document might be more similar to your query than the recent ones.

Another way would be to use a Function Score Query together with your regular query to boost documents that are closer to a certain refference date (e.g. now). But figuring out the right amount of boost and how you combine the function score with your regular score requires some tweaking.

Hope this helps.

Thanks for your reply!
Now i use GaussDateDecayFunction together with my query. And try to get the result I want.As you say,how to combine the function score with my regular score and figuring out the right boost is a key point. Thank you again for your tips!