I have a 60-bit (minutes in an hour) field that I would like to aggregate with a bit-wise or
operator so that the end result is a bit set if any of the contributing values had that bit set.
The representation of the bit field isn't determined yet, but it would be nice to have it be somewhat compact as there are a lot of records entering the aggregation.
Say we have three documents with a bitfield taking the binary values: 0001
, 1001
, 1100
. A bit-wise or
aggregation would combine them to the value 1101
- a bit is true if that bit is set in any value. Much like a sum aggregation but bit-wise operation instead.
I've considered a bit-position array (position present if bit is set) but it gets a little verbose.
Scripted metric aggregation could be possible but I'm a little at a loss of how to implement it.
Scripted metric agg would look something like this broken painless code:
"aggs": {
"profit": {
"scripted_metric": {
"init_script": "minagg = 0L",
"map_script": "minagg = minagg | minutes",
}
}
}
Thanks for looking.
The scripted metric aggregation handles this. With an index with the following mapping...
... this aggregation delivers the or'd values: