elasticsearch v0.1.1 Elasticsearch.Index.Bulk 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/1, 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

Link to this function encode(struct, index) View Source
encode(struct(), 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(%Post{id: "my-id"}, "my-index")
{:ok, """
{"create":{"_type":"post","_index":"my-index","_id":"my-id"}}
{"title":null,"author":null}
"""}

iex> Bulk.encode(123, "my-index")
{:error,
  %Protocol.UndefinedError{description: "",
  protocol: Elasticsearch.Document, value: 123}}

Same as encode/1, but returns the request and raises errors.

Example

iex> Bulk.encode!(%Post{id: "my-id"}, "my-index")
"""
{"create":{"_type":"post","_index":"my-index","_id":"my-id"}}
{"title":null,"author":null}
"""

iex> Bulk.encode!(123, "my-index")
** (Protocol.UndefinedError) protocol Elasticsearch.Document not implemented for 123. This protocol is implemented for: Post
Link to this function upload(index_name, store, sources, errors \\ []) View Source

Uploads all the data from the list of sources to the given index. Data for each source will be fetched using the configured :store.