View Source Snap.Search (Snap v0.9.0)

Performs searches against an ElasticSearch cluster.

Summary

Functions

Runs a count of the documents in an index, using an optional query.

Makes a search against an ElasticSearch cluster and parses the response.

Functions

Link to this function

count(cluster, index_or_alias, query \\ %{}, params \\ [], headers \\ [], opts \\ [])

View Source

Runs a count of the documents in an index, using an optional query.

Link to this function

search(cluster, index_or_alias, query, params \\ [], headers \\ [], opts \\ [])

View Source
@spec search(
  cluster :: module(),
  index_or_alias :: String.t(),
  query :: map(),
  params :: Keyword.t(),
  headers :: Keyword.t(),
  opts :: Keyword.t()
) :: {:ok, Snap.SearchResponse.t()} | Snap.Cluster.error()

Makes a search against an ElasticSearch cluster and parses the response.

Performs a search against an index using a POST request, and parses the response into a Snap.SearchResponse.

Snap.SearchResponse implements Enumerable, so you can count and iterate directly on the struct.

Examples

query = %{query: %{match_all: %{}}}
{:ok, response} = Snap.Search.search(Cluster, "index", query)

IO.inspect(response.took)
Enum.each(response, fn hit -> IO.inspect(hit.score) end)