Find consecutive field values in sorted collection of documents

I have documents such as the following that I can sorted by id (sequence number) or dateRecorded. Was sold is boolean. Using elasticsearch aggregations, how do I compute the longest consecutive wasSold = true or wasSold = false or some other field on the document, when I sort documents or filter with time frames.

{
  id: 1234343434,
  height: 12,
  width: 1,
  dateRecorded: "1565664751639",
  wasSold: true
}