Clinton Gormley > Elastic-Model-0.50 > Elastic::Model::Namespace

Download:
Elastic-Model-0.50.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 0.50   Source  

NAME ^

Elastic::Model::Namespace - Class-to-type map

VERSION ^

version 0.50

SYNOPSIS ^

Namespace declaration

    package MyApp;

    use Elastic::Model;

    has_namespace 'myapp' => {
        user    => 'MyApp::User',
        post    => 'MyApp::Post',
    };

    no Elastic::Model;

Using the namespace

    $namespace  = $model->namespace('myapp');

    $index      = $namespace->index($index_name);
    $alias      = $namespace->alias($alias_name);

    $name       = $namespace->name;
    @domains    = $namespace->all_domains
    \%types     = $namespace->types;
    @types      = $namespace->all_types;
    \%mappings  = $namespace->mappings( @types );

DESCRIPTION ^

Elastic::Model::Namespace maps your doc classes to types (like a database table) in Elasticsearch. For instance, you could map your class MyApp::User to type user.

This class <=> type mapping is applied to all domains known to the Namespace. Each domain has a single Namespace, and all documents stored in that domain (index or index alias) are handled by the same Namespace. A namespace/type/id combination must be unique across all domains associated with a Namespace.

A Namespace "knows" about Domains via the "name" attribute. Either you can have a single index called $namespace->name, OR an alias called $namespace->name which points to multiple indices. Additional domains (indices or aliases) can be specified with "fixed_domains"

Namespaces are also used to create, update or delete indices or "alias()" in aliases.

See Elastic::Manual::Intro, Elastic::Model for how to declare your namespaces, and Elastic::Manual::Scaling for more about namespaces, indices and aliases.

ATTRIBUTES ^

name

    $name = $namespace->name

The name of the namespace. This attribute is important! It is used in a couple of places:

As the "main domain" name

A domain is like a database handle - you need a domain to create, retrieve, update and deleted individual docs from Elasticsearch. The domain name can be an index or an alias. Several domains (indices/aliases) can be associated with a namespace. The easiest way to do this it to make the "main domain name" (ie the namespace "name") an alias which points to all the indices in that namespace.

See "Namespaces, domains, aliases and indices" in Elastic::Manual::Scaling "fixed_domains" and "all_domains()" for more.

As the scope name

A scope is an optional in-memory cache. The cache ID uses the object's type, ID and namespace "name" to group objects, so the ID must be unique across all indices in a namespace.

types

all_types

class_for_type

    \%types     = $namespace->types
    @type_names = $namespace->all_types
    $class      = $namespace->class_for_type($type_name)

A hashref whose keys are the type names in Elasticsearch, and whose values are wrapped doc classes, eg the class MyApp::User wrapped by "wrap_doc_class()" in Elastic::Model::Role::Model.

fixed_domains

    \@fixed_domains = $namespace->fixed_domains;

While the preferred method for associating domains with a namespace is via an alias named after the namespace "name", you can include a list of other domains (indices or aliases) in the namespace declaration:

    has_namespace 'myapp' => {
        user    => 'MyApp::User'
    },
    fixed_domains => ['index_1','alias_2'];

See "Namespaces, domains, aliases and indices" in Elastic::Manual::Scaling "name" and "all_domains()" for more.

METHODS ^

index()

    $index = $namespace->index;
    $index = $namespace->index('index_name');

Creates an Elastic::Model::Index object for creating and administering indices in the Elasticsearch cluster. The $index name is either the "name" of the $namespace or the value passed in to "index()".

alias()

    $alias = $namespace->alias;
    $alias = $namespace->alias('alias_name');

Creates an Elastic::Model::Alias object for creating and administering index aliases in the Elasticsearch cluster. The $alias name is either the "name" of the $namespace or the value passed in to "alias()".

all_domains()

    @domains = $namespace->all_domains();

Returns all domain names known to the namespace. It does this by retrieving all indices and aliases associated with the namespace "name" and the "fixed_domains" (if any).

all_live_indices()

    @indices = $namespace->all_live_indices();

Queries Elasticsearch to find all existing indices related to the namespace

mappings()

    \%mapping = $namespace->mappings();
    \%mapping = $namespace->mappings(@type_names);

Generates the type mappings for the specified list of types, or, for all types known to the namespace if not specified.

SEE ALSO ^

AUTHOR ^

Clinton Gormley <drtech@cpan.org>

COPYRIGHT AND LICENSE ^

This software is copyright (c) 2014 by Clinton Gormley.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

syntax highlighting: