Elastex v0.2.0 Elastex.Document
Follows the Elasticsearch Document API.
Summary
Functions
Performs index, create, delete, or update operations in a single call
Deletes a document from the index based on its id
Checks whether a specific document exists
Extends the url of document builder
Gets a document from the index based on its id
Adds a document in a specific index, automatically generating an id
Adds a document in a specific index using the supplied id
Gets multiple documents based on docs array information
Gets multiple documents based on index and docs array information
Gets multiple documents based on index, type and docs array information
Gets multiple term vectors at once using body options only
Gets multiple term vectors at once using body options and an index
Gets multiple term vectors at once using body options, an index and type
Adds params to document builders
Returns information and statistics on terms in the fields of a particular document
Returns information and statistics on terms in the fields of a particular document using body options
Updates a document based on its id
Types
bulk_action ::
:document_update |
:document_index |
:document_create |
:document_delete
int_or_string :: non_neg_integer | String.t
Functions
Specs
bulk([%Elastex.Builder{action: bulk_action, body: term, headers: term, id: term, index: term, method: term, options: term, params: term, type: term, url: term}]) :: %Elastex.Builder{action: :document_bulk, body: String.t, headers: term, id: term, index: term, method: :post, options: term, params: term, type: term, url: String.t}
Performs index, create, delete, or update operations in a single call.
Examples
iex> bulk_requests = [
...> Elastex.Document.delete("twitter", "tweet", 5),
...> Elastex.Document.index(%{hello: "world"}, "twitter", "tweet")
...> ]
iex> Elastex.Document.bulk(bulk_requests)
%Elastex.Builder {
url: "_bulk",
body: "{\"delete\":{\"_type\":\"tweet\",\"_index\":\"twitter\",\"_id\":5}}\n{\"index\":{\"_type\":\"tweet\",\"_index\":\"twitter\"}}\n{\"hello\":\"world\"}\n",
method: :post,
action: :document_bulk
}
Specs
delete(String.t, String.t, int_or_string) :: %Elastex.Builder{action: :document_delete, body: term, headers: term, id: int_or_string, index: String.t, method: :delete, options: term, params: term, type: String.t, url: String.t}
Deletes a document from the index based on its id.
Examples
iex> Elastex.Document.delete("twitter", "tweet", 5)
%Elastex.Builder {
url: "twitter/tweet/5",
method: :delete,
action: :document_delete,
index: "twitter",
type: "tweet",
id: 5
}
Specs
exists(String.t, String.t, int_or_string) :: %Elastex.Builder{action: term, body: term, headers: term, id: term, index: term, method: :head, options: term, params: term, type: term, url: String.t}
Checks whether a specific document exists.
Examples
iex> Elastex.Document.exists("twitter", "tweet", 5)
%Elastex.Builder {
url: "twitter/tweet/5",
method: :head
}
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 document builder
Examples
iex> builder = %Elastex.Builder{url: "twitter"}
iex> Elastex.Document.extend_url(builder, ["tweet"])
%Elastex.Builder {
url: "twitter/tweet"
}
Specs
get(String.t, String.t, int_or_string) :: %Elastex.Builder{action: term, body: term, headers: term, id: term, index: term, method: :get, options: term, params: term, type: term, url: String.t}
Gets a document from the index based on its id.
Examples
iex> Elastex.Document.get("twitter", "tweet", 5)
%Elastex.Builder {
url: "twitter/tweet/5",
method: :get
}
Specs
Adds a document in a specific index, automatically generating an id.
Examples
iex> Elastex.Document.index(%{hello: "world"}, "twitter", "tweet")
%Elastex.Builder {
url: "twitter/tweet",
body: %{hello: "world"},
method: :post,
action: :document_index,
index: "twitter",
type: "tweet"
}
Specs
index(map, String.t, String.t, int_or_string) :: %Elastex.Builder{action: :document_index, body: map, headers: term, id: int_or_string, index: String.t, method: :put, options: term, params: term, type: String.t, url: String.t}
Adds a document in a specific index using the supplied id.
Examples
iex> Elastex.Document.index(%{hello: "world"}, "twitter", "tweet", 5)
%Elastex.Builder {
url: "twitter/tweet/5",
body: %{hello: "world"},
method: :put,
action: :document_index,
index: "twitter",
type: "tweet",
id: 5
}
Specs
mget(map) :: %Elastex.Builder{action: term, body: map, headers: term, id: term, index: term, method: :get, options: term, params: term, type: term, url: String.t}
Gets multiple documents based on docs array information.
Examples
iex> docs = %{docs: [%{_index: "website", _type: "blog", _id: 2}]}
iex> Elastex.Document.mget(docs)
%Elastex.Builder {
url: "_mget",
body: %{docs: [%{_index: "website", _type: "blog", _id: 2}]},
method: :get
}
Specs
Gets multiple documents based on index and docs array information.
Examples
iex> docs = %{docs: [%{_type: "blog", _id: 2}]}
iex> Elastex.Document.mget(docs, "website")
%Elastex.Builder {
url: "website/_mget",
body: %{docs: [%{_type: "blog", _id: 2}]},
method: :get,
}
Specs
Gets multiple documents based on index, type and docs array information.
Examples
iex> docs = %{ids: ["1", "2"]}
iex> Elastex.Document.mget(docs, "website", "blog")
%Elastex.Builder {
url: "website/blog/_mget",
body: %{ids: ["1", "2"]},
method: :get
}
Specs
mterm_vectors(map) :: %Elastex.Builder{action: term, body: map, headers: term, id: term, index: term, method: :get, options: term, params: term, type: term, url: String.t}
Gets multiple term vectors at once using body options only.
Examples
iex> body = %{doc: [%{_index: "twitter", _type: "tweet", _id: 2}]}
iex> Elastex.Document.mterm_vectors(body)
%Elastex.Builder {
url: "_mtermvectors",
body: %{doc: [%{_index: "twitter", _type: "tweet", _id: 2}]},
method: :get
}
Specs
Gets multiple term vectors at once using body options and an index.
Examples
iex> body = %{doc: [%{_index: "twitter", _type: "tweet", _id: 2}]}
iex> Elastex.Document.mterm_vectors(body, "twitter")
%Elastex.Builder {
url: "twitter/_mtermvectors",
body: %{doc: [%{_index: "twitter", _type: "tweet", _id: 2}]},
method: :get
}
Specs
Gets multiple term vectors at once using body options, an index and type.
Examples
iex> body = %{doc: [%{_index: "twitter", _type: "tweet", _id: 2}]}
iex> Elastex.Document.mterm_vectors(body, "twitter", "tweet")
%Elastex.Builder {
url: "twitter/tweet/_mtermvectors",
body: %{doc: [%{_index: "twitter", _type: "tweet", _id: 2}]},
method: :get
}
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 document builders
Examples
iex> builder = %Elastex.Builder{}
iex> Elastex.Document.params(builder, [q: "user:mike"])
%Elastex.Builder {
params: [q: "user:mike"]
}
Specs
term_vectors(String.t, String.t, int_or_string) :: %Elastex.Builder{action: term, body: term, headers: term, id: term, index: term, method: :get, options: term, params: term, type: term, url: String.t}
Returns information and statistics on terms in the fields of a particular document.
Examples
iex> Elastex.Document.term_vectors("twitter", "tweet", "1")
%Elastex.Builder {
url: "twitter/tweet/1/_termvectors",
method: :get
}
Specs
term_vectors(map, String.t, String.t, int_or_string) :: %Elastex.Builder{action: term, body: map, headers: term, id: term, index: term, method: :get, options: term, params: term, type: term, url: String.t}
Returns information and statistics on terms in the fields of a particular document using body options.
Examples
iex> body = %{fields: ["text"], "positions": true}
iex> Elastex.Document.term_vectors(body, "twitter", "tweet", "1")
%Elastex.Builder {
url: "twitter/tweet/1/_termvectors",
body: %{fields: ["text"], "positions": true},
method: :get
}
Specs
update(map, String.t, String.t, int_or_string) :: %Elastex.Builder{action: :document_update, body: map, headers: term, id: int_or_string, index: String.t, method: :post, options: term, params: term, type: String.t, url: String.t}
Updates a document based on its id.
Examples
iex> Elastex.Document.update(%{doc: %{name: "new_name"}}, "twitter", "tweet", 5)
%Elastex.Builder {
url: "twitter/tweet/5/_update",
body: %{doc: %{name: "new_name"}},
method: :post,
action: :document_update,
index: "twitter",
type: "tweet",
id: 5
}