exlasticsearch v1.6.2 ExlasticSearch.Response View Source

Base module for ES response parsing. Works off a few macros, schema/1, field/1, has_many/2, has_one/2

The usage is more or less:

use ExlasticSearch.Response

schema do
  field :total

  has_many :hits, HitsModule
end

This will define:

  • a struct for carrying the response
  • parse/2 - converts a json decoded map from ES to the given response struct, and converting any models appropriately
  • to_model/2 - performs model conversion if possible (defaults to no-op)

Link to this section Summary

Functions

Safe conversion of string keyed ES response maps to structifiable atom keyed maps

Adds a simple field attribute

Adds a has_many relation or the parser, which assumes a list value

Adds a has_one relation or the parser

Utility for recursively parsing response associations

Opens up the schema definition macro. Once closed, the following will be defined

Link to this section Functions

Link to this function convert_keys(conversion_table, map) View Source

Safe conversion of string keyed ES response maps to structifiable atom keyed maps

Adds a simple field attribute

Link to this macro has_many(field, parser) View Source (macro)

Adds a has_many relation or the parser, which assumes a list value

Accepts:

  • field - the name of the relation
  • parser - module of the responsible parser for parsing it
Link to this macro has_one(field, parser) View Source (macro)

Adds a has_one relation or the parser

Accepts:

  • field - the name of the relation
  • parser - module of the responsible parser for parsing it
Link to this function parse_associations(response, associations, model) View Source

Utility for recursively parsing response associations

Opens up the schema definition macro. Once closed, the following will be defined:

  • __schema__(:parse_spec) - A table for converting string keyed maps to atom keyed
  • __schema__(:attributes) - basic field attributes
  • __schema__(:associations) - a table of associations for the response, along with the responsible parser