Elasticsearch.Index.Bulk (elasticsearch v1.1.0) View Source
Functions for creating bulk indexing requests.
Link to this section Summary
Functions
Encodes a given variable into an Elasticsearch bulk request. The variable
must implement Elasticsearch.Document
.
Same as encode/3
, but returns the request and raises errors.
Uploads all the data from the list of sources
to the given index.
Data for each source
will be fetched using the configured :store
.
Link to this section Functions
Specs
encode(Elasticsearch.Cluster.t(), struct(), String.t(), String.t()) :: {:ok, String.t()} | {:error, Error.t()}
Encodes a given variable into an Elasticsearch bulk request. The variable
must implement Elasticsearch.Document
.
Examples
iex> Bulk.encode(Cluster, %Post{id: "my-id"}, "my-index")
{:ok, """
{"create":{"_index":"my-index","_id":"my-id"}}
{"title":null,"doctype":{"name":"post"},"author":null}
"""}
iex> Bulk.encode(Cluster, 123, "my-index")
{:error,
%Protocol.UndefinedError{description: "",
protocol: Elasticsearch.Document, value: 123}}
Same as encode/3
, but returns the request and raises errors.
Example
iex> Bulk.encode!(Cluster, %Post{id: "my-id"}, "my-index")
"""
{"create":{"_index":"my-index","_id":"my-id"}}
{"title":null,"doctype":{"name":"post"},"author":null}
"""
iex> Bulk.encode!(Cluster, 123, "my-index")
** (Protocol.UndefinedError) protocol Elasticsearch.Document not implemented for 123 of type Integer
Specs
upload( Elasticsearch.Cluster.t(), index_name :: String.t(), Elasticsearch.Store.t(), list() ) :: :ok | {:error, [map()]}
Uploads all the data from the list of sources
to the given index.
Data for each source
will be fetched using the configured :store
.