diff --git a/lib/console/logs/provider/elastic.ex b/lib/console/logs/provider/elastic.ex index 28cbf1484..d1340fee0 100644 --- a/lib/console/logs/provider/elastic.ex +++ b/lib/console/logs/provider/elastic.ex @@ -18,12 +18,19 @@ defmodule Console.Logs.Provider.Elastic do @spec query(t(), Query.t) :: {:ok, [Line.t]} | Console.error def query(%__MODULE__{connection: %{index: index}, client: client}, %Query{} = q) do - case Snap.Search.search(client, index, build_query(q)) do + case search(client, index, build_query(q)) do {:ok, hits} -> {:ok, format_hits(hits)} {:error, err} -> {:error, "failed to query elasticsearch: #{inspect(err)}"} end end + defp search(client, index, query) do + case client.post("/#{index}/_search", query) do + {:ok, response} -> {:ok, Snap.SearchResponse.new(response)} + err -> err + end + end + defp format_hits(%Snap.SearchResponse{hits: %Snap.Hits{hits: hits}}) do Enum.map(hits, fn %Snap.Hit{fields: fields} -> %Line{ diff --git a/lib/console/logs/provider/elastic/client.ex b/lib/console/logs/provider/elastic/client.ex index 97ab427bd..6488567e2 100644 --- a/lib/console/logs/provider/elastic/client.ex +++ b/lib/console/logs/provider/elastic/client.ex @@ -17,7 +17,7 @@ defmodule Console.Logs.Provider.Elastic.Client do ], &elem(&1, 1)) end - def config(), do: Process.get(@key) + def config(), do: Process.get(@key) || [] def json_library(), do: Jason