elasticsearch v0.1.1 Elasticsearch.Document protocol View Source
A protocol for converting a struct into an Elasticsearch document.
Example
defimpl Elasticsearch.Document, for: MyStruct do
def id(struct), do: struct.id
def type(_struct), do: "struct"
def parent(_struct), do: false
def encode(struct) do
%{
id: struct.id,
name: struct.name
}
end
end
Link to this section Summary
Functions
Returns a map of fields, which will be converted to JSON and stored in Elasticsearch as a document
Returns the Elasticsearch _id
for the item
Returns the parent ID of the document, or false
if there is no parent
Returns the Elasticsearch _type
for the object
Link to this section Types
Link to this section Functions
Returns a map of fields, which will be converted to JSON and stored in Elasticsearch as a document.
Example
def encode(item) do
%{
title: item.title,
author: item.author
}
end
Returns the parent ID of the document, or false
if there is no parent.
Examples
# For structs that have parents
def parent(%{parent_id: id}) when id != nil, do: id
# For structs that don't have parents
def parent(_item), do: false