View on
MetaCPAN is shutting down
For details read Perl NOC. After June 25th this page will redirect to
Clinton Gormley > Elastic-Model > Elastic::Model::TypeMap::Objects



Annotate this POD

View/Report Bugs
Module Version: 0.52   Source  


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


version 0.52


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


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

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


Clinton Gormley <>


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.

syntax highlighting: