NAME

Elastic::Model::TypeMap::Objects - Type maps for objects and Moose classes

VERSION

version 0.52

DESCRIPTION

Elastic::Model::TypeMap::Objects provides mapping, inflation and deflation for Moose-based classes and objects. It is loaded automatically by Elastic::Model::TypeMap::Default.

TYPES

Moose classes

has 'bar' => (
    is  => 'rw,
    isa => 'Bar'
);

If Bar is a Moose class, then its attributes will be introspected and the mapping will look like:

{
    type        => 'object',
    dynamic     => 'strict',
    properties  => {
        ... mapping for Bar's attributes...
    }
}

By default, all attributes are included. You can control the attribute list with:

has 'bar' => (
    is              => 'rw,
    isa             => 'Bar',
    include_attrs   => [],              # no attributes
  | include_attrs   => ['foo','bar']    # just 'foo' and 'bar'
  | exclude_attrs   => ['foo','bar']    # all except 'foo' and 'bar'
);

You can control the mapping for individual attributes in Moose classes with the Elastic::Model::Trait::Field trait:

package Bar;

use Moose;

has 'foo' => (
    is              => 'rw,
    isa             => 'Str',
    trait           => ['Elastic::Model::Trait::Field']
);

Elastic::Doc classes

Elastic::Doc classes work in exactly the same way as other Moose classes except

  • You don't need to specify the Elastic::Model::Trait::Field trait - it is added automatically.

  • The UID field is always included, unless you specifically list it in exclude_attrs.

By default, all the attributes of an Elastic::Doc class will be included. For instance, if we have two classes: User and Post, and the Post class has a user attribute. Because all the attributes of the $user are also indexed in the $post object, you can search for Posts which have been written by a User whose name is "john".

This also means that if a User updates their name, then you need to reindex all of their Posts.

If you don't want to include any attributes, then you can just specify: include_attrs => []. The UID will still be indexed, meaning that you can still do:

$user_name = $post->user->name;

Moose Roles and non-Moose classes

Moose roles and non-Moose classes must provide custom mappings, deflators and inflators

AUTHOR

Clinton Gormley <drtech@cpan.org>

COPYRIGHT AND LICENSE

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.