Last active
July 21, 2022 19:16
-
-
Save rugyoga/4df6bcfb5e45e6955c5f1d6784ccd2cb to your computer and use it in GitHub Desktop.
Query the size of the result set and choose between stream_one and stream_many accordingly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@spec stream(ES.query_t(), ES.index_t(), ES.consumer_t()) :: {:ok, any()} | {:error, any()} | |
def stream(query, index, consumer) do | |
case count(query, index) do | |
{:ok, count} -> | |
if count > ES.max_results() do | |
stream_many(query, index, consumer, count) | |
else | |
stream_one(query, index, consumer) | |
end | |
error -> | |
error | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment