danielberkompas/elasticsearch-elixir

Handle Get API document not found error

Closed this issue ยท 3 comments

When a document is not found via the Get API the following exception is raised -

iex(1)> Elasticsearch.get(MyApp.ElasticsearchCluster, "/index-name/_doc/123")

** (FunctionClauseError) no function clause matching in Elasticsearch.Exception.build/2

    The following arguments were given to Elasticsearch.Exception.build/2:

        # 1
        %{
          "_id" => "123",
          "_index" => "index-name",
          "_type" => "_doc",
          "found" => false
        }

        # 2
        nil

    Attempted function clauses (showing 4 out of 4):

        defp build(%{"error" => error} = response, query) when is_map(error)
        defp build(%{"error" => error}, query) when is_binary(error)
        defp build(%{"result" => type}, query)
        defp build(error, query) when is_binary(error)

    (elasticsearch) lib/elasticsearch/exception.ex:35: Elasticsearch.Exception.build/2
    (elasticsearch) lib/elasticsearch/exception.ex:22: Elasticsearch.Exception.exception/1
    (elasticsearch) lib/elasticsearch.ex:389: Elasticsearch.format/1

@danielberkompas Created a pull request for this issue, let me know if this can be merged.

Just released v0.4.1 with this fix. Thanks!

Thanks!

โค๏ธ ๐Ÿ’™ ๐Ÿ’œ ๐Ÿ’› ๐Ÿ’š