         %{type: "null", identifier: "0"}
     end
   end
+
+
+  def to_hits(%{ hits: %{ hits: hits }}), do: hits
+
+  def to_resource(%{ _source: %{ resource: resource } }), do: resource
+
 end
    case HTTPoison.get("localhost:9200/idai-field/resource/" <> id) do

      {:ok, %HTTPoison.Response{status_code: 200, body: body}} ->
        %{ _source: %{ resource: resource }} = atomize Poison.decode! body
        resource

      {:ok, %HTTPoison.Response{status_code: 404}} ->
        %{type: "null", identifier: "0"}

    case HTTPoison.get("localhost:9200/idai-field/resource/_search") do

      {:ok, %HTTPoison.Response{status_code: 200, body: body}} ->
        Poison.decode!(body)
        |> atomize
        |> to_hits
        |> Enum.map(&to_resource/1)

      {:ok, %HTTPoison.Response{status_code: 404}} ->
        []
