Skip to content

Instantly share code, notes, and snippets.

@gokhangirgin
Created March 18, 2017 13:37
Show Gist options
  • Save gokhangirgin/59e52c2484c0cdf6836a6bc9ab7f89f3 to your computer and use it in GitHub Desktop.
Save gokhangirgin/59e52c2484c0cdf6836a6bc9ab7f89f3 to your computer and use it in GitHub Desktop.
Elasticsearch simple Elixir wrapper
defmodule MyApp.Elasticsearch do
use HTTPoison.Base
@es_config Application.get_env(:myapp, :elasticsearch)
def process_url(url) do
"#{@es_config[:url]}/#{@es_config[:type]}#{url}"
end
defp process_request_headers(headers) when is_map(headers) do
Enum.into(headers, [{"Content-Type", "application/json"}])
end
defp process_request_headers(headers) do
[{"Content-Type", "application/json"}]
end
def process_request_body(body) when is_map(body) do
request_body = body |> Poison.encode!
if Mix.env == :dev do
IO.inspect request_body
end
request_body
end
def process_request_body(body), do: body
def process_response_body(body) do
response_body = body |> Poison.decode!
if Mix.env == :dev do
IO.inspect response_body
end
response_body
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment