Elastex v0.2.0 Elastex.Search
Follows the Elasticsearch Search API.
Summary
Functions
Executes a query to get the number of matches for that query
Executes a query to get the number of matches for that query with a body
Executes a query to get the number of matches for that query with a body and index
Executes a query to get the number of matches for that query with body, index, and type
Computes a score explanation for a query and a specific document
Computes a score explanation for a query and a specific document
Extends the url of search builder
Executes several search request in a single call
Adds params to search builders
Executes a search query
Executes a search query with a body
Executes a search query with a body and index
Executes a search query with a body, index, and type
Gets search hits from http response if present. Returns error tuple with http response if not present
Returns indices and shards that a search request would be executed against using an index
Returns indices and shards that a search request would be executed against using an index and a type
Suggests similar looking terms based on a provided text
Allows use of mustache templating language to pre-render search requests
Validates a potentially expensive query without executing it
Validates a potentially expensive query without executing it
Validates a potentially expensive query without executing it with index
Validates a potentially expensive query without executing it with index
Types
body :: map | nil
http_response ::
{:ok, HTTPoison.Response} |
{:error, HTTPoison.Error}
int_or_string :: non_neg_integer | String.t
Functions
Specs
count :: %Elastex.Builder{action: term, body: term, headers: term, id: term, index: term, method: :post, options: term, params: term, type: term, url: String.t}
Executes a query to get the number of matches for that query.
Useful with params search.
Examples
iex> Elastex.Search.count()
%Elastex.Builder {
url: "_count",
method: :post
}
Specs
Executes a query to get the number of matches for that query with a body.
Examples
iex> body = %{"query" => %{term: %{user: "kimchy"}}}
iex> Elastex.Search.count(body)
%Elastex.Builder {
url: "_count",
body: %{"query" => %{term: %{user: "kimchy"}}},
method: :post
}
Specs
Executes a query to get the number of matches for that query with a body and index.
Examples
iex> body = %{"query" => %{term: %{user: "kimchy"}}}
iex> Elastex.Search.count(body, "twitter")
%Elastex.Builder {
url: "twitter/_count",
body: %{"query" => %{term: %{user: "kimchy"}}},
method: :post
}
Specs
Executes a query to get the number of matches for that query with body, index, and type.
Examples
iex> body = %{"query" => %{term: %{user: "kimchy"}}}
iex> Elastex.Search.count(body, "twitter", "tweet")
%Elastex.Builder {
url: "twitter/tweet/_count",
body: %{"query" => %{term: %{user: "kimchy"}}},
method: :post
}
Specs
explain(String.t, String.t, int_or_string) :: %Elastex.Builder{action: term, body: body, headers: term, id: term, index: term, method: :post, options: term, params: term, type: term, url: String.t}
Computes a score explanation for a query and a specific document.
Examples
iex> Elastex.Search.explain("twitter", "tweet", 1)
%Elastex.Builder {
url: "twitter/tweet/1/_explain",
body: nil,
method: :post
}
Specs
Computes a score explanation for a query and a specific document.
Examples
iex> body = %{"query" => %{term: %{user: "kimchy"}}}
iex> Elastex.Search.explain(body, "twitter", "tweet", 1)
%Elastex.Builder {
url: "twitter/tweet/1/_explain",
body: %{"query" => %{term: %{user: "kimchy"}}},
method: :post
}
Specs
extend_url(%Elastex.Builder{action: term, body: term, headers: term, id: term, index: term, method: term, options: term, params: term, type: term, url: term}, [String.t]) :: %Elastex.Builder{action: term, body: term, headers: term, id: term, index: term, method: term, options: term, params: term, type: term, url: String.t}
Extends the url of search builder
Examples
iex> builder = %Elastex.Builder{url: "twitter"}
iex> Elastex.Search.extend_url(builder, ["tweet"])
%Elastex.Builder {
url: "twitter/tweet"
}
Specs
multi_search([%Elastex.Builder{action: :search_query, body: term, headers: term, id: term, index: term, method: term, options: term, params: term, type: term, url: term}]) :: %Elastex.Builder{action: :multi_search, body: String.t, headers: term, id: term, index: term, method: :post, options: term, params: term, type: term, url: String.t}
Executes several search request in a single call.
Examples
iex> query_builders = [
...> Elastex.Search.query(%{hello: "world"}),
...> Elastex.Search.query(%{hello: "world"}, "twitter", "tweet")
...> ]
iex> Elastex.Search.multi_search(query_builders)
%Elastex.Builder {
url: "_msearch",
body: "{}\n{\"hello\":\"world\"}\n{\"index\":\"twitter\"}\n{\"hello\":\"world\"}\n",
method: :post,
action: :multi_search
}
Specs
params(%Elastex.Builder{action: term, body: term, headers: term, id: term, index: term, method: term, options: term, params: term, type: term, url: term}, keyword(String.t)) :: %Elastex.Builder{action: term, body: term, headers: term, id: term, index: term, method: term, options: term, params: keyword(String.t), type: term, url: term}
Adds params to search builders
Examples
iex> builder = %Elastex.Builder{}
iex> Elastex.Search.params(builder, [q: "user:mike"])
%Elastex.Builder {
params: [q: "user:mike"]
}
Specs
query :: %Elastex.Builder{action: :search_query, body: term, headers: term, id: term, index: term, method: :post, options: term, params: term, type: term, url: String.t}
Executes a search query.
Useful for URI searches.
Examples
iex> Elastex.Search.query
%Elastex.Builder {
url: "_search",
method: :post,
action: :search_query,
}
with params
iex> Elastex.Search.query |> Elastex.Search.params([q: "user:kimchy"])
%Elastex.Builder {
url: "_search",
method: :post,
action: :search_query,
params: [q: "user:kimchy"]
}
Specs
Executes a search query with a body.
Examples
iex> body = %{query: %{term: %{user: "kimchy"}}}
iex> Elastex.Search.query(body)
%Elastex.Builder {
url: "_search",
body: %{query: %{term: %{user: "kimchy"}}},
method: :post,
action: :search_query,
}
Specs
Executes a search query with a body and index.
Examples
iex> body = %{query: %{term: %{user: "kimchy"}}}
iex> Elastex.Search.query(body, "twitter")
%Elastex.Builder {
url: "twitter/_search",
body: %{query: %{term: %{user: "kimchy"}}},
method: :post,
index: "twitter",
action: :search_query
}
Specs
Executes a search query with a body, index, and type.
Examples
iex> body = %{query: %{term: %{user: "kimchy"}}}
iex> Elastex.Search.query(body, "twitter", "tweet")
%Elastex.Builder {
url: "twitter/tweet/_search",
body: %{query: %{term: %{user: "kimchy"}}},
index: "twitter",
type: "tweet",
action: :search_query,
method: :post
}
Specs
query_hits(http_response) ::
{:ok, map} |
{:error, String.t}
Gets search hits from http response if present. Returns error tuple with http response if not present.
Specs
Returns indices and shards that a search request would be executed against using an index.
Examples
iex> Elastex.Search.shards("twitter")
%Elastex.Builder {
url: "twitter/_search_shards",
method: :get,
index: "twitter",
type: ""
}
Specs
Returns indices and shards that a search request would be executed against using an index and a type.
Examples
iex> Elastex.Search.shards("twitter", "tweet")
%Elastex.Builder {
url: "twitter/tweet/_search_shards",
method: :get,
index: "twitter",
type: "tweet"
}
Specs
Suggests similar looking terms based on a provided text.
Examples
iex> body = %{"my-suggestion" => %{text: "hi", term: %{field: "body"}}}
iex> Elastex.Search.suggest(body)
%Elastex.Builder {
url: "_suggest",
body: %{"my-suggestion" => %{text: "hi", term: %{field: "body"}}},
method: :post
}
Specs
Allows use of mustache templating language to pre-render search requests.
Examples
iex> body = %{inline: %{query: %{match: %{title: "{{query_string}}"}}}}
iex> Elastex.Search.template(body)
%Elastex.Builder {
url: "_search/template",
body: %{inline: %{query: %{match: %{title: "{{query_string}}"}}}},
method: :post
}
Specs
Validates a potentially expensive query without executing it.
Examples
iex> Elastex.Search.validate()
%Elastex.Builder {
url: "_validate/query",
body: nil,
method: :post
}
Specs
Validates a potentially expensive query without executing it.
Examples
iex> body = %{"query" => %{term: %{user: "kimchy"}}}
iex> Elastex.Search.validate(body)
%Elastex.Builder {
url: "_validate/query",
body: %{"query" => %{term: %{user: "kimchy"}}},
method: :post
}
Specs
Validates a potentially expensive query without executing it with index.
Examples
iex> body = %{"query" => %{term: %{user: "kimchy"}}}
iex> Elastex.Search.validate(body, "twitter")
%Elastex.Builder {
url: "twitter/_validate/query",
body: %{"query" => %{term: %{user: "kimchy"}}},
method: :post
}
Specs
Validates a potentially expensive query without executing it with index.
Examples
iex> body = %{"query" => %{term: %{user: "kimchy"}}}
iex> Elastex.Search.validate(body, "twitter", "tweet")
%Elastex.Builder {
url: "twitter/tweet/_validate/query",
body: %{"query" => %{term: %{user: "kimchy"}}},
method: :post
}