exlasticsearch v1.10.1 ExlasticSearch.Model View Source

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

Link to this section 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

Link to this section Functions

Link to this function es_decode(source, model) View Source

Converts a search result to model’s search result type

Link to this function index_version(type, version) View Source
Link to this macro indexes(type, block) View Source (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
Link to this macro mapping(name, props \\ []) View Source (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")
Link to this macro options(options) View Source (macro)
Link to this macro settings(settings) View Source (macro)

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

Link to this macro versions(index) View Source (macro)