Last active
July 21, 2022 20:01
-
-
Save rugyoga/7965504b91c92732901a85c443ab7dfb to your computer and use it in GitHub Desktop.
Sample controller leveraging ElasticSearch.stream, chunker and S3.upload
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
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