NAME
Elastic::Model::Domain - The domain (index or alias) where your docs are stored.
VERSION
version 0.51
SYNOPSIS
Get a domain instance
$domain = $model->domain('myapp');
Create a new doc/object
$user = $domain->new_doc( user => \%args );
$user->save;
# or:
$user = $domain->create( user => \%args);
Retrieve a doc by ID
$user = $domain->get( $type => $id );
$user = $domain->try_get( $type => $id ); # return undef if missing
Check if a doc exists
$bool = $domain->exists( $type => $id );
Delete a doc by ID
$uid = $domain->delete( $type => $id );
$user = $domain->try_delete( $type => $id ); # return undef if missing
Create a view on the current domain
$view = $domain->view(%args);
DESCRIPTION
A "domain" is like a database handle used for CRUD (creating, updating or deleting) individual objects or documents. The $domain->name
can be the name of an index or an index alias. A domain can only belong to a single namespace.
NOTE: If $domain->name
is an alias, it can only point to a single index.
ATTRIBUTES
name
A $domain->name
must be either the name of an index or of an index alias which points to a single index. The index or alias must exist, and must be known to the namespace.
namespace
The Elastic::Model::Namespace object to which this domain belongs.
INSTANTIATOR
new()
$domain = $model->domain_class->new({
name => $domain_name,
namespace => $namespace,
});
Although documented here, you shouldn't need to call new()
yourself. Instead you should use "domain()" in Elastic::Model::Role::Model:
$domain = $model->domain($domain_name);
METHODS
new_doc()
$doc = $domain->new_doc( $type => \%args );
new_doc()
will create a new object in the class that maps to type $type
, passing %args
to new()
in the associated class. For instance:
$user = $domain->new_doc(
user => {
id => 1,
name => 'Clint',
}
);
create()
$doc = $domain->create( $type => \%args );
This is the equivalent of:
$doc = $domain->new_doc( $type => \%args )->save();
get()
$doc = $domain->get( $type => $id );
$doc = $domain->get( $type => $id, routing => $routing, ... );
Retrieves a doc of type $type
with ID $id
from index $domain->name
or throws an exception if the doc doesn't exist. See "get_doc()" in Elastic::Model::Role::Store for more parameters which can be passed.
try_get()
$doc = $domain->try_get( $type => $id );
$doc = $domain->try_get( $type => $id, routing => $routing, ... );
Retrieves a doc of type $type
with ID $id
from index $domain->name
or returns undef if the doc doesn't exist.
exists()
$bool = $domain->exists( $type => $id );
$bool = $domain->exists( $type => $id, routing => $routing, ... );
Checks if a doc of type $type
with ID $id
exists in index $domain->name
. See "doc_exists()" in Elastic::Model::Role::Store for more parameters which can be passed.
delete()
$uid = $domain->delete( $type => $id );
$uid = $domain->delete( $type => $id, routing => $routing, ... );
Deletes a doc of type $type
with ID $id
from index $domain->name
or throws an exception if the doc doesn't exist. See "delete_doc()" in Elastic::Model::Role::Store for more parameters which can be passed.
try_delete()
$uid = $domain->try_delete( $type => $id );
$uid = $domain->try_delete( $type => $id, routing => $routing, ... );
Deletes a doc of type $type
with ID $id
from index $domain->name
or returns undef if the doc doesn't exist.
view()
$view = $domain->view(%args)
Creates a view with the "domain" in Elastic::Model::View set to $domain->name
. A view
is used for searching docs in a $domain
.
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.