View Source ExlasticSearch.Model (exlasticsearch v2.2.3)

Base macro for generating elasticsearch modules. Is intended to be used in conjunction with a Ecto model (although that is not strictly necessary).

It includes three primary macros:

The usage is something like this

indexes :my_type do
  settings Application.get_env(:some, :settings)

  mapping :column
  mapping :other_column, type: :keyword
end

This will set up settings and mappings for index my_types with type my_type (specify the singularized type in the macro, so pluralization works naturally).

The following functions will also be created:

  • __es_mappings__/0 - map of all fully specified mappings for the given type
  • __mappings__/0 - columns with mappings for the given type
  • __es_index__/0 - the elasticsearch index for this model
  • __es_index__/1 - the elasticsearch index for reads/writes when performing zero-downtime updates (pass either :read or :index respectively)
  • __doc_type__/0 - the default document type for searches in es_index()
  • __es_settings__/0 - the settings for the index of this model

Summary

Functions

Converts a search result to model's search result type

Opens up index definition for the current model. Will name the index and generate metadata attributes for the index based on subsequent calls to settings/1 and mappings/2.

Adds a new mapping to the ES schema. The type of the mapping will be inferred automatically, unless explictly set in props.

A map of index settings. Structure is the same as specified by ES.

Functions

ecto_to_es(type)

es_decode(source, model)

Converts a search result to model's search result type

index_version(type)

index_version(type, version)

indexes(type, block)

(macro)

Opens up index definition for the current model. Will name the index and generate metadata attributes for the index based on subsequent calls to settings/1 and mappings/2.

Accepts

  • type - the indexes type (and index name will be type <> "s")
  • block - the definition of the index

mapping(name, props \\ [])

(macro)

Adds a new mapping to the ES schema. The type of the mapping will be inferred automatically, unless explictly set in props.

Accepts:

  • name - the name of the mapping
  • props - is a map/kw list of ES mapping configuration (e.g. search_analyzer: "my_search_analyzer", type: "text")

mapping_template(arg)

options(options)

(macro)

settings(settings)

(macro)

A map of index settings. Structure is the same as specified by ES.

versions(index)

(macro)