View Source Snap.Multi (Snap v0.9.0)

Provides a high level abstraction over the Multi Search API which allows the user to perform multiple searches in a single request.

Example usage:

Multi.new()
|> Multi.add(query_1, id: "query-1")
|> Multi.add(query_2, id: "query-2")
|> Multi.run(Cluster, index)

This returns a Snap.Multi.Response, with a searches field containing a list of responses.

{:ok, %Snap.Multi.Response{searches: [
  {"query-1", %Snap.SearchResponse{...}},
  {"query-2", %Snap.SearchResponse{...}}
]}}

Each query can be named, using any value you like, by passing an id: "foo" into Multi.add. The list in Snap.Multi.Response contains tuple pairs where the first value is the ID and the second is the result of the query.

If you choose not to name a query the ID in the tuple will be nil.

If your query IDs are unique you can convert this to a Map for easy lookup later using Enum.into(response.searches, %{}).

Summary

Functions

Append to a Snap.Multi request. The body is required. If you pass an id into the headers, this will be used to name the query in the responses list and won't be passed through as a header in the request.

Build a Snap.Multi request.

Perform the Snap.Multi request. This returns {:ok, Snap.Multi.Response} or an error.

Types

@type t() :: %Snap.Multi{searches: list()}

Functions

Link to this function

add(multi, body, headers \\ [])

View Source
@spec add(t(), map(), Keyword.t()) :: t()

Append to a Snap.Multi request. The body is required. If you pass an id into the headers, this will be used to name the query in the responses list and won't be passed through as a header in the request.

@spec new() :: t()

Build a Snap.Multi request.

Link to this function

run(multi, cluster, index_or_alias, params \\ [], headers \\ [], opts \\ [])

View Source
@spec run(t(), atom(), String.t(), Keyword.t(), Keyword.t(), Keyword.t()) ::
  {:ok, Snap.Multi.Response.t()} | {:error, Snap.Cluster.error()}

Perform the Snap.Multi request. This returns {:ok, Snap.Multi.Response} or an error.