Elastic::Model::Namespace - Class-to-type map
version 0.52
package MyApp; use Elastic::Model; has_namespace 'myapp' => { user => 'MyApp::User', post => 'MyApp::Post', }; no Elastic::Model;
$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 );
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.
MyApp::User
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.
domain
namespace
type
id
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"
$namespace->name
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.
$name = $namespace->name
The name of the namespace. This attribute is important! It is used in a couple of places:
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.
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 = $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 = $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.
$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()".
$index
$namespace
$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()".
$alias
@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).
@indices = $namespace->all_live_indices();
Queries Elasticsearch to find all existing indices related to the namespace
\%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.
Elastic::Manual::Intro
Elastic::Model::Domain
Elastic::Model::Index
Elastic::Model::Alias
Clinton Gormley <drtech@cpan.org>
This software is copyright (c) 2015 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.
To install Elastic::Model, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Elastic::Model
CPAN shell
perl -MCPAN -e shell install Elastic::Model
For more information on module installation, please visit the detailed CPAN module installation guide.