radar / elastic

A thin veneer over HTTPotion that talks to Elastic Search

Home Page:https://hex.pm/packages/elastic

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Handle error case for search in Document.API?

Anderssorby opened this issue · comments

Regarding this line:

{:ok, 200, %{"hits" => %{"hits" => hits}}} = result

Could we handle the error case for the Document.API.search as well? If for example the index doesn't exist it creates a nasty exception.

Something like:

case result do
          {:error, code, error} ->
            {:error, code, error}
          {:ok, 200, %{"hits" => %{"hits" => hits}}} ->
            Enum.map(hits, fn %{"_source" => source, "_id" => id} ->
              into_struct(id, source)
            end)
end

I can make a PR. Then you can have the option to deal with the errors without breaking existing code.

Yes please do submit a PR for this.