Skip to content

Commit

Permalink
work around snap
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeljguarino committed Jan 10, 2025
1 parent ba868ce commit 24ba524
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
9 changes: 8 additions & 1 deletion lib/console/logs/provider/elastic.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
2 changes: 1 addition & 1 deletion lib/console/logs/provider/elastic/client.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 24ba524

Please sign in to comment.