ElasticMapping

A simple mappings builder for Elasticsearch


License
Other
Install
pip install ElasticMapping==1.2

Documentation

ElasticMapping

A simple mapping builder for Elasticsearch. Install with pip install elasticmapping.

Synopsis

from elasticmapping import ElasticMapping
from elasticmapping.types import STRING, INTEGER, FLOAT

# An mapping which forms an ES doc_type
class DocMapping(ElasticMapping):
    __doc_type__ = 'doc_mapping'

    # Top-level attributes
    name = STRING
    ID = INTEGER

    # Nested documents
    nested_document = Nest(
        float_type=FLOAT,
        interger_type=INTEGER
    )

# Print out JSON ready for ES
print DocMapping.json(indent=4)

Check out the full example.

Types

  • STRING
  • BOOLEAN
  • FLOAT, DOUBLE, INTEGER, LONG, SHORT, BYTE
  • DATE, TIME, DATETIME (format = date_optional_time)

ElasticQuery support

ElasticMapping can be combined with my other ES library, ElasticQuery. When ElasticQuery is provided mappings, it limits the fields it can search/aggregate on to that of the mapping - this helps to prevent unexpected errors. For more details see the query example. Nested fields are not checked.