I'm using StackOverflow as a motivating example because it's similar enough to my situation. Here's a screenshot of StackOverflow's search for context:
The "Question" document schema includes basics like title/description/author. Additionally, there's a "vote count" and (in my case) whether or not the current user has upvoted a question.
Vote count could be implemented as a simple integer on the "Question" document. However, the setting of vote count should be idempotent due to the impossibility of exactly-once delivery. Therefore vote count will be implemented as a list of UserIds who have upvoted that question. I was initially trying to figure out if you could do aggregations on a field of a document, but now I think runtime fields are the best way forwards, especially because you can index the resulting count (and therefore easily sort by popularity).
To return if the current user has upvoted a question, I plan on using a runtime field (again). I'll pass a
script_fields parameter containing the current user's id as part of the request. The runtime field will be a Painless script that takes the provided UserId parameter and searches the Question document's
ListOfUserIdsWhoUpvoted for that UserId.
Does this runtime field approach sound good, or is there a better way? Would this be impossible prior to 7.12, when runtime fields were introduced?