The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

ElasticSearchX::Model::Document

VERSION

version 0.0.3

SYNOPSIS

 package MyClass;
 use Moose;
 use ElasticSearchX::Model::Document;
 use ElasticSearchX::Model::Document::Types qw(Location);
 use MooseX::Types -declare => ['Resources'];
 use MooseX::Types::Structured qw(Dict Optional);
 use MooseX::Types::Moose qw(Str ArrayRef);

 subtype Resources,
  as Dict [ license => Optional [ ArrayRef [Str] ],
            homepage => Optional [Str],
            bugtracker => Optional [ Dict [ web => Str, mailto => Str ] ] ];

 has default  => ( is => 'ro' );
 has date     => ( is => 'ro', isa => 'DateTime' );
 has location => ( is => 'ro', isa => Location );
 has res      => ( is => 'ro', isa => Resources );
 has abstract => ( is => 'ro', analyzer => 'lowercase' );

DESCRIPTION

This class extends Moose to include meta information for ElasticSearch. By default, each attribute is treated as property of an ElasticSearch type (i.e. the ElasticSearchX::Model::Document::Trait::Attribute trait is applied). The type name is derived from the class name. See ElasticSearchX::Model::Document::Trait::Class.

See "ATTRIBUTES" in ElasticSearchX::Model::Document::Trait::Attribute for a full list of attribute options available.

ATTRIBUTES

index

 $document->index($model->index('index_v2'));
 $document->put;

The ElasticSearchX::Model::Index object this document belongs to. This attribute is writeable, which allows you to reindex a document to a different index. Make sure that the type is part of the new index. Otherwise indexing is likely to fail.

_id

This is a read-only attribute that holds the value of the id of the document. If you want to set the id by yourself, create an attribute in your document class which has the id attribute set to 1. Otherwise the id will be generated by ElasticSearch.

 has id => ( is => 'ro', id => 1 );

METHODS

put

This puts a document to the ElasticSearch server. It calls "get_data" in ElasticSearchX::Model::Document::Trait::Class to retrieve the data from an ElasticSearchX::Model::Document object.

delete

Delete the document from the index.

AUTHOR

Moritz Onken

COPYRIGHT AND LICENSE

This software is Copyright (c) 2011 by Moritz Onken.

This is free software, licensed under:

  The (three-clause) BSD License