NAME
ElasticSearchX::Model::Document
VERSION
version 0.0.5
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
create
create( { %qs } )
Create a new document. If the document already exists (based on the id), an ElasticSearch::Error::Conflict expection is thrown.
update
update( { %qs } )
Update an existing document. Throws an ElasticSearch::Error::Conflict if there is a version mismatch. This happens if a new version of the document was pushed by someone else. If you don't care about a version mismatch, either pass version => undef
or use "put". You can also set a version explicitly with version => $version
.
put
put( { %qs } )
This puts a document to the ElasticSearch server. Use this to update or create a document. It calls "get_data" in ElasticSearchX::Model::Document::Trait::Class to retrieve the data from an ElasticSearchX::Model::Document object.
%qs
are optional parameters that are passed on to "ElasticSearch" in index().
delete
delete( { %qs } )
Delete the document from the index.
AUTHOR
Moritz Onken
COPYRIGHT AND LICENSE
This software is Copyright (c) 2012 by Moritz Onken.
This is free software, licensed under:
The (three-clause) BSD License