Skip to content

Instantly share code, notes, and snippets.

@rugyoga
Last active July 21, 2022 19:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rugyoga/4df6bcfb5e45e6955c5f1d6784ccd2cb to your computer and use it in GitHub Desktop.
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
@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