How to sort by a derived value that includes a moving date?

Hi there, (sorry for all the questions.. for those regular peeps that keep seeing me pop up :slight_smile: )

I have a requirement to sort the results returned by ElasticSearch by a special value i define, let's call it 'X'.

Now - the problem is, 'X' is a value derived based on:

  1. field A in the document (which is a 'term')
  2. field B (which is a 'date')
  3. the current date (UTC)

So, the problem is obviously 3. The date always changes, therefore i'm not sure how to include this in the sort, since it's not part of the document.

Do i need to use a 'script' here? Will that perform well?

The only other idea that came to mind is to calculate the value nightly, and store that in each document. But that has a few drawbacks:

  • i need to have something running in the background to update this value
  • could be a lot of documents to update (60%+ every night).
  • i lose precision for the value depending on how long between script runs. (if i run nightly, value is 23 hours 'stale')

Any advice?

Thanks

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