elastic icon indicating copy to clipboard operation
elastic copied to clipboard

Handle error case for search in Document.API?

Open Anderssorby opened this issue 5 years ago • 2 comments

Regarding this line: https://github.com/radar/elastic/blob/1e2c7a3fe7b28bfa6cc574b10fd7bc6dca3dadfa/lib/elastic/document/api.ex#L190

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.

Anderssorby avatar Feb 05 '20 12:02 Anderssorby

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.

Anderssorby avatar Feb 05 '20 12:02 Anderssorby

Yes please do submit a PR for this.

radar avatar Feb 06 '20 05:02 radar