Streams documents from a search query using the scroll API.
Returns a lazy Stream that yields Snap.Hit structs one at a time,
transparently fetching subsequent batches via Snap.Search.scroll/6 as
needed, then clearing the scroll cursor via Snap.Search.clear_scroll/5
when the stream is exhausted, terminated early, or raises.
Unlike most functions in Snap, errors are not returned as {:error, _}
tuples — lazy enumerables can't surface errors mid-iteration. Instead, any
underlying request failure raises the corresponding exception (typically
Snap.ResponseError) when the consumer pulls the next element.
Summary
Functions
@spec stream( cluster :: module(), index_or_alias :: String.t(), query :: map(), opts :: Keyword.t() ) :: Enumerable.t()
Returns a lazy stream of Snap.Hit structs matching query in index_or_alias.
Options
:scroll— TTL string for the server-side cursor, refreshed on each continuation. Defaults to"1m".:params— extra query params merged into the initial search and each scroll continuation.:headers— passed through to the underlying requests.:opts— request opts passed through to the underlying HTTP client.
Examples
query = %{"query" => %{"match_all" => %{}}, "size" => 100}
Snap.Scroll.stream(Cluster, "products", query)
|> Stream.map(& &1.source)
|> Enum.each(&IO.inspect/1)