You can't directly close a window early based on content in Apache Beam's built-in windowing. Interval windows have a fixed duration once it is assigned. Probably the alternative way but more complex is using a custom WindowFn that tracks the number of elements assigned to each window and closes the window when the condition is met. This involves overriding the assignWindows and potentially other methods of the WindowFn interface.