Skip to content

Instantly share code, notes, and snippets.

@rugyoga
Last active July 21, 2022 20:01
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/7965504b91c92732901a85c443ab7dfb to your computer and use it in GitHub Desktop.
Save rugyoga/7965504b91c92732901a85c443ab7dfb to your computer and use it in GitHub Desktop.
Sample controller leveraging ElasticSearch.stream, chunker and S3.upload
defmodule Controller do
@four_megabytes 4*1024*1024
def find_all(params) do
query(params) |> ElasticSearch.stream(params.index, &consumer(params, &1))
end
def query(params) do
%{term: %{params.query_term => params.query_value}}
end
def consumer(params, stream) do
stream
|> Stream.map(&Poison.encode!(&1["_source"]))
|> chunker(@four_megabytes, false)
|> S3.upload(params.bucket, params.filename)
|> ExAws.request()
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment