Accurate and relevant user-defined sorting

Hey guys, quite new to ES.

I have an app that supports user-provided queries, user-provided filters, and user-provided sorts. The query is fine in multi_match, and filters are good in the filter query. My main issue is the user-provided sorts.

Users interacting with my app can choose a field to sort by and the order (from a predefined list of options, of course). Some are numbers (e.g. like count, views) and others are dates (e.g. creation date), and order is asc/desc.

When I try sorting based on the fields, the date fields appear to behave oddly (with numbers it works fine). My dates are ISO dates (for context, passed from mongodb via monsatche, with a default pipeline to keep the subset I need for search), and when I try using the sort option with order: “desc” and a format of strict_date_optional_time_nanos I get inconsistent results (something from 2 months ago, followed by 10 months ago, followed by 1 month ago).

If I in stead try to use the field for boosting (e.g. gauss) it seems like the results are in the opposite direction (ascending in stead of descending).

My query looks like this:


{
  query: {
    bool: {
      filter: [user-selected filters],
      must: { multi_match: { query: user-query } },
    }
  },
  sort: [user-provided sort with _score tie breaker (either just order if number, or order with the format if date]
}

If I try to use the boosting approach, I remove the sort and in stead wrap the query in a function_score with funcs being a single-element array (field_value_factor for numbers, gauss for dates). Example:

gauss: {
  [sort]: { // user-selected date field
	scale: order === "desc" ? "30d" : "730d",
	offset: order === "desc" ? "7d" : "0d",
	decay: 0.5,
	origin: order === "desc" ? "now" : "some-past-date"
  }
}

Am I doing something wrong? I know that boosting is generally less appropriate for sorting because it's not "absolute" like sorting.

What is the correct way to sort results based on user-provided sorts in a way that would maintain accuracy and relevance, but still respect the user-defined sort?