Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

We’re showing branches in this repository, but you can also compare across forks.

base: 9e91f08870
...
compare: 48c7bbee7d
  • 17 commits
  • 13 files changed
  • 0 commit comments
  • 1 contributor
4 Changes
View
@@ -1,3 +1,7 @@
+0.1.1 - 2012-03-30
+ - $type->refresh sets the refresh qs to a true value
+ - query_type attribute
+
0.1.0 - 2012-01-14
- BREAKING CHANGE:
attributes on the Set class will now clone the Set instance.
6 dist.ini
View
@@ -3,7 +3,7 @@ author = Moritz Onken
license = BSD
copyright_holder = Moritz Onken
-version = 0.1.0
+version = 0.1.1
[Prereqs / TestRequires]
File::Find = 0
@@ -28,10 +28,10 @@ List::MoreUtils = 0
List::Util = 0
Module::Find = 0
Moose = 2.02
-MooseX::Attribute::Deflator = 2.1.7
+MooseX::Attribute::Deflator = 2.2.0
MooseX::Attribute::Chained = 1.0.1
MooseX::Types = 0
-MooseX::Types::ElasticSearch = 0
+MooseX::Types::ElasticSearch = 0.0.2
MooseX::Types::Moose = 0
MooseX::Types::Structured = 0
Scalar::Util = 0
37 lib/ElasticSearchX/Model/Document.pm
View
@@ -7,27 +7,42 @@ use Moose 1.15 ();
use Moose::Exporter;
use ElasticSearchX::Model::Document::Trait::Class;
use ElasticSearchX::Model::Document::Trait::Attribute;
-use ElasticSearchX::Model::Document::Types qw();
+use ElasticSearchX::Model::Document::Types ();
+use Module::Find ();
my ( undef, undef, $init_meta ) = Moose::Exporter->build_import_methods(
- install => [qw(import unimport)],
- with_meta => [qw(has)],
- class_metaroles => {
- class => ['ElasticSearchX::Model::Document::Trait::Class']
- }, );
+ install => [qw(import unimport)],
+ with_meta => [qw(has)],
+ class_metaroles =>
+ { class => ['ElasticSearchX::Model::Document::Trait::Class'] },
+);
+
+my %attr_traits = map {
+ Class::Load::load_class($_);
+ my ($name) = ( $_ =~ /::(\w+)$/ );
+ lc($name) => $_
+ } Module::Find::findallmod(
+ 'ElasticSearchX::Model::Document::Trait::Field');
sub has {
my $meta = shift;
my $name = shift;
Moose->throw_error('Usage: has \'name\' => ( key => value, ... )')
- if @_ % 2 == 1;
+ if @_ % 2 == 1;
my %options = ( definition_context => Moose::Util::_caller_info(), @_ );
$options{traits} ||= [];
- push(@{$options{traits}}, 'ElasticSearchX::Model::Document::Trait::Attribute')
- if($options{property} || !exists $options{property});
+ push(
+ @{ $options{traits} },
+ 'ElasticSearchX::Model::Document::Trait::Attribute'
+ ) if ( $options{property} || !exists $options{property} );
delete $options{property};
+ for ( grep { $attr_traits{$_} } keys %options ) {
+ push( @{ $options{traits} }, $attr_traits{$_} );
+ #(my $class_trait = $attr_traits{$_}) =~ s/::Field::/::Class::/;
+ #Moose::Util::apply_all_roles($meta, $class_trait);
+ }
my $attrs = ( ref($name) eq 'ARRAY' ) ? $name : [ ($name) ];
$meta->add_attribute( $_, %options ) for @$attrs;
}
@@ -36,7 +51,7 @@ sub init_meta {
my $class = shift;
my %p = @_;
Moose::Util::ensure_all_roles( $p{for_class},
- qw(ElasticSearchX::Model::Document::Role) );
+ qw(ElasticSearchX::Model::Document::Role) );
$class->$init_meta(%p);
}
@@ -131,4 +146,4 @@ C<%qs> are optional parameters that are passed on to L<index()/ElasticSearch>.
=head2 delete( { %qs } )
-Delete the document from the index.
+Delete the document from the index.
28 lib/ElasticSearchX/Model/Document/Role.pm
View
@@ -16,8 +16,24 @@ has index => (
is => 'rw'
);
-has _id => ( is => 'ro' );
-has _version => ( is => 'ro' );
+has _id => (
+ is => 'ro',
+ property => 0,
+ source_only => 1,
+ traits => [
+ 'ElasticSearchX::Model::Document::Trait::Attribute',
+ 'ElasticSearchX::Model::Document::Trait::Field::ID',
+ ],
+);
+has _version => (
+ is => 'ro',
+ property => 0,
+ source_only => 1,
+ traits => [
+ 'ElasticSearchX::Model::Document::Trait::Attribute',
+ 'ElasticSearchX::Model::Document::Trait::Field::Version',
+ ],
+);
sub update {
my $self = shift;
@@ -67,13 +83,15 @@ sub _put {
my ( $self, $qs ) = @_;
my $id = $self->meta->get_id_attribute->get_value($self);
my $parent = $self->meta->get_parent_attribute;
+ my $data = $self->meta->get_data($self);
+ $qs = { %{ $self->meta->get_query_data($self) }, %{ $qs || {} } };
return (
index => $self->index->name,
type => $self->meta->short_name,
$id ? ( id => $id ) : (),
- data => $self->meta->get_data($self),
+ data => $data,
$parent ? ( parent => $parent->get_value($self) ) : (),
- %{ $qs || {} },
+ %$qs,
);
}
@@ -84,7 +102,7 @@ sub delete {
index => $self->index->name,
type => $self->meta->short_name,
id => $self->_id,
- %$qs
+ %{ $qs || {} },
);
return $self;
}
57 lib/ElasticSearchX/Model/Document/Set.pm
View
@@ -22,7 +22,8 @@ has filter => (
traits => [qw(ChainedClone)]
);
-has [qw(from size)] => ( isa => 'Int', is => 'rw', traits => [qw(ChainedClone)] );
+has [qw(from size)] =>
+ ( isa => 'Int', is => 'rw', traits => [qw(ChainedClone)] );
has [qw(fields sort)] => (
isa => 'ArrayRef',
@@ -34,7 +35,8 @@ sub add_sort { push( @{ $_[0]->sort }, $_[1] ); return $_[0]; }
sub add_field { push( @{ $_[0]->fields }, $_[1] ); return $_[0]; }
-has query_type => ( isa => QueryType, is => 'rw', traits => [qw(ChainedClone)] );
+has query_type =>
+ ( isa => QueryType, is => 'rw', traits => [qw(ChainedClone)] );
has mixin => ( is => 'ro', isa => 'HashRef', traits => [qw(ChainedClone)] );
@@ -45,6 +47,23 @@ sub raw {
shift->inflate(0);
}
+has _refresh =>
+ ( isa => 'Bool', default => 0, is => 'rw', traits => [qw(ChainedClone)] );
+
+sub refresh {
+ shift->_refresh(1);
+}
+
+sub _build_qs {
+ my ( $self, $qs ) = @_;
+ $qs ||= {};
+
+ # we only want to set qs if they are not the default
+ $qs->{refresh} = 1 if ( $self->_refresh );
+ $qs->{query_type} = $self->query_type if ( $self->query_type );
+ return $qs;
+}
+
sub _build_query {
my $self = shift;
my $query
@@ -67,13 +86,13 @@ sub _build_query {
sub put {
my ( $self, $args, $qs ) = @_;
my $doc = $self->new_document($args);
- $doc->put($qs);
+ $doc->put( $self->_build_qs($qs) );
return $doc;
}
sub new_document {
my ( $self, $args ) = @_;
- return $self->type->new_object( %$args, index => $self->index );
+ return $self->type->name->new( %$args, index => $self->index );
}
sub inflate_result {
@@ -83,19 +102,22 @@ sub inflate_result {
$type = $type ? $index->get_type($type) : $self->type;
my $id = $type->get_id_attribute;
my $parent = $type->get_parent_attribute;
- return $type->new_object(
- { %{ $res->{_source} || {} },
+ my $fields = { %{ $res->{_source} || {} }, %{ $res->{fields} || {} } };
+ return $type->name->new(
+ { %$fields,
index => $index,
_id => $res->{_id},
_version => $res->{_version},
- $id ? ( $id->name => $res->{_id} ) : (),
- $parent ? ( $parent->name => $res->{_parent} ) : (),
+ $fields->{_timestamp} ? ( timestamp => $fields->{_timestamp} ) : (),
+ $id ? ( $id->name => $res->{_id} ) : (),
+ $parent ? ( $parent->name => $res->{_parent} ) : (),
}
);
}
sub get {
my ( $self, $args, $qs ) = @_;
+ $qs = $self->_build_qs($qs);
my ($id);
my ( $index, $type ) = ( $self->index->name, $self->type->short_name );
@@ -132,6 +154,7 @@ sub get {
sub all {
my ( $self, $qs ) = @_;
+ $qs = $self->_build_qs($qs);
my ( $index, $type ) = ( $self->index->name, $self->type->short_name );
my $res = $self->es->transport->request(
{ method => 'POST',
@@ -147,6 +170,7 @@ sub all {
sub first {
my ( $self, $qs ) = @_;
+ $qs = $self->_build_qs($qs);
my @data = $self->size(1)->all($qs);
return undef unless (@data);
return $data[0] if ( $self->inflate );
@@ -154,12 +178,14 @@ sub first {
}
sub count {
- my $self = shift;
+ my ( $self, $qs ) = @_;
+ $qs = $self->_build_qs($qs);
my ( $index, $type ) = ( $self->index->name, $self->type->short_name );
my $res = $self->es->transport->request(
{ method => 'POST',
cmd => "/$index/$type/_search",
data => { %{ $self->_build_query }, size => 0 },
+ qs => $qs,
}
);
return $res->{hits}->{total};
@@ -167,12 +193,13 @@ sub count {
sub delete {
my ( $self, $qs ) = @_;
+ $qs = $self->_build_qs($qs);
my $query = $self->_build_query;
return $self->es->delete_by_query(
index => $self->index->name,
type => $self->type->short_name,
query => $query->{filter} ? { filtered => $query } : $query->{query},
- %{ $qs || {} },
+ %$qs,
);
}
@@ -181,7 +208,7 @@ sub scroll {
return ElasticSearchX::Model::Scroll->new(
set => $self,
scroll => $scroll || '1m',
- qs => { version => 1, %{ $qs || {} } },
+ qs => $self->_build_qs( { version => 1, %{ $qs || {} } } ),
);
}
@@ -260,6 +287,8 @@ build a C<filtered> query, which performs far better.
=head2 sort
+=head2 query_type
+
These attributes are passed directly to the ElasticSearch search request.
=head2 mixin
@@ -371,3 +400,9 @@ object.
Don't inflate returned results. This is a convenience
method around L</inflate>.
+
+=head2 refresh
+
+This will add the C<refresh> query parameter to all requests.
+
+ $users->refresh->put( { nickname => 'mo' } );
62 lib/ElasticSearchX/Model/Document/Trait/Class.pm
View
@@ -4,6 +4,7 @@ package ElasticSearchX::Model::Document::Trait::Class;
use Moose::Role;
use List::Util ();
use Carp;
+use Eval::Closure;
has set_class => ( is => 'ro', builder => '_build_set_class', lazy => 1 );
has short_name => ( is => 'ro', builder => '_build_short_name', lazy => 1 );
@@ -74,15 +75,74 @@ sub _build_all_properties {
sub get_data {
my ( $self, $instance ) = @_;
+ return $self->name->_get_data($instance)
+ if ( $self->has_method('_get_data') );
return {
map {
- my $deflate = $_->deflate($instance);
+ my $deflate
+ = $_->is_inflated($instance)
+ || $_->is_required && !$_->has_value($instance)
+ ? $_->deflate($instance)
+ : $_->get_raw_value($instance);
defined $deflate ? ( $_->name => $deflate ) : ();
} grep { $_->has_value($instance) || $_->is_required }
$self->get_all_properties
};
}
+sub _inline_get_data {
+ my $self = shift;
+ my @code = ( 'sub {', 'my $data = {};' );
+ my @type_constraints, my @type_coercions;
+ my $i = 0;
+ foreach my $property ( $self->get_all_properties ) {
+ push( @type_constraints,
+ $property->has_type_constraint
+ ? $property->type_constraint->_compiled_type_constraint
+ : undef );
+ push( @type_coercions,
+ $property->type_constraint
+ ? $property->type_constraint->has_coercion
+ ? $property->type_constraint->coercion
+ ->_compiled_type_coercion
+ : undef
+ : undef );
+ my $has_value = $property->_inline_instance_has('$_[1]');
+ my @is_inflated = $property->_inline_instance_is_inflated(
+ '$_[1]',
+ '$type_constraints[' . $i . ']',
+ '$type_coercions[' . $i . ']',
+ );
+ my @get_raw_value = $property->_inline_instance_get('$_[1]');
+ push( @code, "if($has_value)" ) unless ( $property->is_required );
+ push( @code,
+ '{',
+ '$data->{"' . quotemeta( $property->name ) . '"} = (',
+ @is_inflated,
+ $property->is_required ? " || !$has_value" : "",
+ ') ? $properties[' . $i . ']->deflate($_[1]) : ',
+ @get_raw_value,
+ ';',
+ 'delete $data->{"' . quotemeta( $property->name ) . '"}',
+ ' unless(defined $data->{"'
+ . quotemeta( $property->name ) . '"});',
+ '}' );
+ $i++;
+ }
+ @code = join( "\n", @code, 'return $data;', '}' );
+ my $evaled = eval_closure(
+ environment => {
+ '@type_coercions' => \@type_coercions,
+ '@type_constraints' => \@type_constraints,
+ '@properties' => [ $self->get_all_properties ],
+ },
+ source => @code,
+ );
+ $self->add_method( _get_data => $evaled );
+}
+
+before make_immutable => \&_inline_get_data if ( $Moose::VERSION >= 2 );
+
1;
=head1 ATTRIBUTES
131 lib/ElasticSearchX/Model/Document/Types.pm
View
@@ -3,7 +3,8 @@ use List::MoreUtils ();
use DateTime::Format::Epoch::Unix;
use DateTime::Format::ISO8601;
use ElasticSearch;
-use MooseX::Attribute::Deflator 2.1.7;
+use MooseX::Attribute::Deflator;
+use MooseX::Attribute::Deflator::Moose;
use DateTime;
use JSON;
use Scalar::Util qw(blessed);
@@ -13,24 +14,71 @@ use MooseX::Types -declare => [
qw(
Type
Types
+ TimestampField
+ TTLField
)
];
-use Sub::Exporter -setup => { exports => [qw(Location QueryType ES Type Types)] };
+use Sub::Exporter -setup => {
+ exports => [
+ qw(
+ Location
+ QueryType
+ ES
+ Type
+ Types
+ TimestampField
+ TTLField
+ )
+ ]
+};
+
+use MooseX::Types::Moose qw/Int Str Bool ArrayRef HashRef/;
+use MooseX::Types::Structured qw(Dict Tuple Optional slurpy);
-use MooseX::Types::Moose qw/Int Str ArrayRef HashRef/;
-use MooseX::Types::Structured qw(Dict Tuple Optional);
+subtype TimestampField, as Dict [
+ enabled => Bool,
+ path => Optional [Str],
+ store => Optional [Bool],
+ index => Optional [Str],
+ slurpy HashRef,
+];
+coerce TimestampField, from Int, via {
+ { enabled => 1, store => 1 };
+};
+coerce TimestampField, from Str, via {
+ { enabled => 1, path => $_, store => 1 };
+};
+coerce TimestampField, from HashRef, via {
+ { enabled => 1, %$_ };
+};
+
+subtype TTLField, as Dict [
+ enabled => Bool,
+ default => Optional [Str],
+ store => Optional [Bool],
+ index => Optional [Str],
+ slurpy HashRef,
+];
+coerce TTLField, from Int, via {
+ { enabled => 1 };
+};
+coerce TTLField, from Str, via {
+ { enabled => 1, default => $_ };
+};
+coerce TTLField, from HashRef, via {
+ { enabled => 1, %$_ };
+};
class_type 'DateTime';
+coerce 'DateTime', from Int, via {
+ DateTime->from_epoch( epoch => $_ / 1000 );
+};
coerce 'DateTime', from Str, via {
- if ( $_ =~ /^\d+$/ ) {
- DateTime::Format::Epoch::Unix->parse_datetime($_);
- }
- else {
- DateTime::Format::ISO8601->parse_datetime($_);
- }
+ DateTime::Format::ISO8601->parse_datetime($_);
};
+
subtype Types, as HashRef ['Object'], where {
!grep { $_->isa('Moose::Meta::Class') } keys %$_;
}, message {
@@ -49,10 +97,9 @@ coerce Types, from ArrayRef ['Str'], via {
my $array = $_;
return {
map {
- my $meta = Class::MOP::Class->initialize( $_ );
+ my $meta = Class::MOP::Class->initialize($_);
$meta->short_name => $meta
- }
- @$array
+ } @$array
};
};
@@ -76,27 +123,49 @@ Moose::Util::TypeConstraints::add_parameterizable_type(
$REGISTRY->get_type_constraint(Type) );
use MooseX::Attribute::Deflator;
-deflate 'Bool', via { $_ ? JSON::XS::true : JSON::XS::false };
-inflate 'Bool', via { $_ ? 1 : 0 };
my @stat
= qw(dev ino mode nlink uid gid rdev size atime mtime ctime blksize blocks);
-deflate 'File::stat', via { return { List::MoreUtils::mesh( @stat, @$_ ) } };
-deflate 'ScalarRef', via { ref $_ ? $$_ : $_ };
-deflate 'HashRef', via { shift->dynamic ? $_ : encode_json($_) };
-inflate 'HashRef', via { shift->dynamic ? $_ : decode_json($_) };
-deflate 'DateTime', via { $_->iso8601 };
-inflate 'DateTime', via { DateTime::Format::ISO8601->parse_datetime($_) };
-deflate Location, via { [ $_->[0] + 0, $_->[1] + 0 ] };
-deflate Type . '[]', via { ref $_ eq 'HASH' ? $_ : $_->meta->get_data($_) };
-deflate 'ArrayRef[]', via {
- my ( $attr, $constraint, $deflate ) = @_;
- return $_ if ( $attr->dynamic );
- $constraint = $constraint->parent
- if ( ref $constraint eq 'MooseX::Types::TypeDecorator' );
- my $value = [@$_];
- $_ = $deflate->( $_, $constraint->type_parameter ) for (@$value);
- return $deflate->( $value, $constraint->parent );
+deflate 'File::stat', via { return { List::MoreUtils::mesh( @stat, @$_ ) } },
+ inline_as {
+ join( "\n",
+ 'my @stat = qw(dev ino mode nlink uid gid',
+ 'rdev size atime mtime ctime blksize blocks);',
+ 'List::MoreUtils::mesh( @stat, @$value )',
+ );
+ };
+deflate [ 'ArrayRef', 'HashRef' ],
+ via { shift->dynamic ? $_ : encode_json($_) }, inline_as {
+ return '$value' if ( $_[0]->dynamic );
+ return 'JSON::XS::encode_json($value)';
+ };
+inflate [ 'ArrayRef', 'HashRef' ],
+ via { shift->dynamic ? $_ : decode_json($_) }, inline_as {
+ return '$value' if ( $_[0]->dynamic );
+ return 'JSON::XS::decode_json($value)';
+ };
+
+deflate 'ArrayRef', via {$_}, inline_as {'$value'};
+inflate 'ArrayRef', via {$_}, inline_as {'$value'};
+
+deflate 'DateTime', via { $_->iso8601 }, inline_as {'$value->iso8601'};
+inflate 'DateTime', via {
+ $_ =~ /^\d+$/
+ ? DateTime->from_epoch( epoch => $_/1000 )
+ : DateTime::Format::ISO8601->parse_datetime($_);
+}, inline_as {
+ q(
+ $value =~ /^\d+$/
+ ? DateTime->from_epoch(epoch => $value/1000)
+ : DateTime::Format::ISO8601->parse_datetime($value)
+ )
};
+deflate Location, via { [ $_->[0] + 0, $_->[1] + 0 ] },
+ inline_as {'[ $value->[0] + 0, $value->[1] + 0 ]'};
+deflate Type . '[]', via { ref $_ eq 'HASH' ? $_ : $_->meta->get_data($_) },
+ inline_as {
+ 'ref $value eq "HASH" ? $value : $value->meta->get_data($value)';
+ };
+
no MooseX::Attribute::Deflator;
1;
15 lib/ElasticSearchX/Model/Role.pm
View
@@ -44,20 +44,17 @@ sub deploy {
);
}
if ( my $alias = $index->alias_for ) {
- my $aliases
- = $self->es->get_aliases( index => $index->name )->{aliases}
- ->{ $index->name };
+ my @aliases
+ = keys %{ $self->es->get_aliases( index => $index->name )
+ || {} };
my $actions = [
( map {
- { remove => { index => $_, alias => $index->name }
- }
- } @$aliases
+ { remove => { index => $_, alias => $index->name } }
+ } @aliases
),
{ add => { index => $alias, alias => $index->name } }
];
- $self->es->aliases(
- actions => $actions
- );
+ $self->es->aliases( actions => $actions );
}
}
return 1;
29 t/document/get_data.t
View
@@ -1,21 +1,25 @@
package MyModel::MyType;
use Moose;
use ElasticSearchX::Model::Document;
+use MooseX::Types::Common::String qw(:all);
-has name => ( is => 'ro', index => 'analyzed' );
+has name => ( is => 'ro', index => 'analyzed', isa => LowerCaseSimpleStr, coerce => 1 );
+MyModel::MyType->meta->make_immutable;
package MyModel::MyClass;
use Moose;
use ElasticSearchX::Model::Document;
use ElasticSearchX::Model::Document::Types qw(:all);
+use MooseX::Types::Moose qw(:all);
-has module => ( is => 'ro', isa => Type ['MyType'] );
+has module => ( is => 'ro', isa => ArrayRef[Type ['MyType']] );
has hash => ( is => 'ro', isa => 'HashRef' );
has hash_dynamic =>
( is => 'ro', isa => 'HashRef', dynamic => 1 );
has author => ( is => 'ro' );
has extra => ( is => 'ro', source_only => 1, dynamic => 1 );
has [qw(bool1 bool2)] => ( is => 'ro', isa => 'Bool' );
+has array => ( is => 'ro', isa => 'ArrayRef[Num]', dynamic => 1 );
MyModel::MyClass->meta->make_immutable;
@@ -38,16 +42,16 @@ my $model = MyModel->new;
{
my $meta = MyModel::MyClass->meta;
my $obj = MyModel::MyClass->new(
- module => MyModel::MyType->new( name => 'foo' ),
+ module => [MyModel::MyType->new( name => 'foo' )],
author => 'me',
);
-
- ok( $meta->get_attribute('module')->has_deflator, 'module has deflator' );
- ok( $meta->get_attribute('module')->has_type_constraint,
+ my $attr = $meta->get_attribute('module');
+ ok( $attr->has_deflator, 'module has deflator' );
+ ok( $attr->has_type_constraint,
'module has tc' );
-
+ ok($attr->is_inflated($obj), 'module is inflated');
is_deeply( $meta->get_data($obj),
- { author => 'me', module => { name => 'foo' } },
+ { author => 'me', module => [{ name => 'foo' }] },
'deflated ok' );
}
@@ -108,4 +112,13 @@ my $model = MyModel->new;
ok($deflated2, "deflated is false");
}
+{
+ my $doc = MyModel::MyClass->new(
+ array => [qw(1 2 3)],
+ index => $model->index('static'),
+ );
+ my $deflate = $doc->meta->get_attribute('array')->deflate($doc);
+ is_deeply($deflate, [qw(1 2 3)]);
+}
+
done_testing;
2  t/document/mapping.t
View
@@ -57,7 +57,7 @@ my $meta = MyClass->meta;
is_deeply(
[ sort map { $_->name } $meta->get_all_properties ],
- [ qw(abstract date default extra loc module modules pod profile res vater)
+ [ qw(_id _version abstract date default extra loc module modules pod profile res vater)
]
);
5 t/document/types.t
View
@@ -10,10 +10,13 @@ is_deeply( Location->coerce( { latitude => 12, longitude => 13 } ),
[ 13, 12 ] );
my $dt = find_type_constraint('DateTime');
-is( $dt->coerce(10)->iso8601, '1970-01-01T00:00:10' );
+is( $dt->coerce(10000)->iso8601, '1970-01-01T00:00:10' );
is( $dt->coerce('1970-01-01T00:00:20')->iso8601, '1970-01-01T00:00:20' );
is( $dt->coerce('1970-01-01')->iso8601, '1970-01-01T00:00:00' );
+ok( find_type_constraint(TTLField)->check( { enabled => 1, foo => 'bar' } ),
+ 'test TTLField' );
+
{
package MyModel::User;
22 t/es/fields.t
View
@@ -0,0 +1,22 @@
+use strict;
+use warnings;
+use lib qw(t/lib);
+use MyModel;
+use Test::Most;
+use DateTime;
+
+my $model = MyModel->testing;
+my $twitter = $model->index('twitter')->type('user');
+ok( $twitter->refresh->put(
+ { nickname => 'mo',
+ name => 'Moritz Onken',
+ }
+ ),
+ 'Put mo ok'
+);
+
+ok( my $user = $twitter->query_type('scan')->fields( ['name'] )->first, 'get name field' );
+
+is($user->name, 'Moritz Onken', 'got field ok');
+
+done_testing;
14 t/lib/MyModel.pm
View
@@ -3,18 +3,28 @@ use Moose;
use Test::More;
use IO::Socket::INET;
use ElasticSearchX::Model;
+use version;
index twitter => ( namespace => 'MyModel' );
sub testing {
my $class = shift;
unless ( IO::Socket::INET->new('127.0.0.1:9900') ) {
- plan skip_all => 'Requires an ElasticSearch server running on port 9900';
+ plan skip_all =>
+ 'Requires an ElasticSearch server running on port 9900';
}
my $model = $class->new( es => ':9900' );
+ my $version
+ = version->parse( $model->es->current_server_version->{number} )
+ ->numify;
+ if ( $version < 0.019002 ) {
+ plan skip_all => 'Requires ElasticSearch 0.19.2';
+ }
+
+ # $model->es->trace_calls(1);
ok( $model->deploy( delete => 1 ), 'Deploy ok' );
return $model;
}
-__PACKAGE__->meta->make_immutable;
+__PACKAGE__->meta->make_immutable;

No commit comments for this range

Something went wrong with that request. Please try again.