I'm trying to implement different types of disproportionality metrics for pharmacovigilance reports in Elasticsearch. These are basically different flavours of significant terms aggregations, and I'm pretty sure I can use custom scoring functions, but I need marginal counts.
The individual documents in elastic are adverse drug reports that have some report meta-data, at least one suspect drug, and at least one reaction term.
I would aggregate first by suspect drug, and then do significant terms aggregation on reactions within each suspect drug bucket. The problem is that I need access to two different background counts for the scoring function. I need the count of all documents without the suspect drug and the count of all documents without the specific reaction that is being scored.
I know I can specify a custom background, but I can't seem to define more than one.
Does anyone have any ideas on how something like this could be implemented?