line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Elastic::Model::Types; |
2
|
|
|
|
|
|
|
$Elastic::Model::Types::VERSION = '0.52'; |
3
|
25
|
|
|
25
|
|
134
|
use strict; |
|
25
|
|
|
|
|
53
|
|
|
25
|
|
|
|
|
732
|
|
4
|
25
|
|
|
25
|
|
132
|
use warnings; |
|
25
|
|
|
|
|
43
|
|
|
25
|
|
|
|
|
632
|
|
5
|
25
|
|
|
25
|
|
21127
|
use Search::Elasticsearch(); |
|
25
|
|
|
|
|
958648
|
|
|
25
|
|
|
|
|
783
|
|
6
|
|
|
|
|
|
|
|
7
|
25
|
|
|
25
|
|
17453
|
use MooseX::Types::Moose qw(HashRef ArrayRef Str Bool Num Int Defined Any); |
|
25
|
|
|
|
|
1378242
|
|
|
25
|
|
|
|
|
278
|
|
8
|
25
|
|
|
25
|
|
190185
|
use MooseX::Types::Structured qw (Dict Optional Map); |
|
25
|
|
|
|
|
11396704
|
|
|
25
|
|
|
|
|
194
|
|
9
|
25
|
|
|
25
|
|
11546
|
use namespace::autoclean; |
|
25
|
|
|
|
|
57
|
|
|
25
|
|
|
|
|
158
|
|
10
|
|
|
|
|
|
|
|
11
|
25
|
|
|
|
|
261
|
use MooseX::Types -declare => [ qw( |
12
|
|
|
|
|
|
|
ArrayRefOfStr |
13
|
|
|
|
|
|
|
Binary |
14
|
|
|
|
|
|
|
Consistency |
15
|
|
|
|
|
|
|
CoreFieldType |
16
|
|
|
|
|
|
|
DynamicMapping |
17
|
|
|
|
|
|
|
ES |
18
|
|
|
|
|
|
|
ES_1x |
19
|
|
|
|
|
|
|
ES_90 |
20
|
|
|
|
|
|
|
FieldType |
21
|
|
|
|
|
|
|
GeoPoint |
22
|
|
|
|
|
|
|
HighlightArgs |
23
|
|
|
|
|
|
|
IndexMapping |
24
|
|
|
|
|
|
|
IndexNames |
25
|
|
|
|
|
|
|
Keyword |
26
|
|
|
|
|
|
|
Latitude |
27
|
|
|
|
|
|
|
Longitude |
28
|
|
|
|
|
|
|
MultiField |
29
|
|
|
|
|
|
|
MultiFields |
30
|
|
|
|
|
|
|
PathMapping |
31
|
|
|
|
|
|
|
Replication |
32
|
|
|
|
|
|
|
SortArgs |
33
|
|
|
|
|
|
|
StoreMapping |
34
|
|
|
|
|
|
|
TermVectorMapping |
35
|
|
|
|
|
|
|
Timestamp |
36
|
|
|
|
|
|
|
UID |
37
|
|
|
|
|
|
|
) |
38
|
25
|
|
|
25
|
|
2694
|
]; |
|
25
|
|
|
|
|
50
|
|
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
my @enums = ( |
41
|
|
|
|
|
|
|
FieldType, |
42
|
|
|
|
|
|
|
[ 'string', 'integer', 'long', 'float', |
43
|
|
|
|
|
|
|
'double', 'short', 'byte', 'boolean', |
44
|
|
|
|
|
|
|
'date', 'binary', 'object', 'nested', |
45
|
|
|
|
|
|
|
'ip', 'geo_point', 'attachment' |
46
|
|
|
|
|
|
|
], |
47
|
|
|
|
|
|
|
CoreFieldType, |
48
|
|
|
|
|
|
|
[ 'string', 'integer', 'long', 'float', |
49
|
|
|
|
|
|
|
'double', 'short', 'byte', 'boolean', |
50
|
|
|
|
|
|
|
'date', 'ip', 'geo_point' |
51
|
|
|
|
|
|
|
], |
52
|
|
|
|
|
|
|
TermVectorMapping, |
53
|
|
|
|
|
|
|
[ 'no', 'yes', 'with_offsets', 'with_positions', 'with_positions_offsets' ], |
54
|
|
|
|
|
|
|
IndexMapping, |
55
|
|
|
|
|
|
|
[ 'analyzed', 'not_analyzed', 'no' ], |
56
|
|
|
|
|
|
|
DynamicMapping, |
57
|
|
|
|
|
|
|
[ 'false', 'strict', 'true' ], |
58
|
|
|
|
|
|
|
PathMapping, |
59
|
|
|
|
|
|
|
[ 'just_name', 'full' ], |
60
|
|
|
|
|
|
|
Replication, |
61
|
|
|
|
|
|
|
[ 'sync', 'async' ], |
62
|
|
|
|
|
|
|
Consistency, |
63
|
|
|
|
|
|
|
[ 'quorum', 'one', 'all' ], |
64
|
|
|
|
|
|
|
); |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
while ( my $type = shift @enums ) { |
67
|
|
|
|
|
|
|
my $vals = shift @enums; |
68
|
|
|
|
|
|
|
subtype( |
69
|
|
|
|
|
|
|
$type, |
70
|
|
|
|
|
|
|
{ as => enum($vals), |
71
|
|
|
|
|
|
|
message => sub { "Allowed values are: " . join '|', @$vals } |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
); |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
class_type ES_1x, { class => 'Search::Elasticsearch::Client::1_0::Direct' }; |
77
|
|
|
|
|
|
|
class_type ES_90, { class => 'Search::Elasticsearch::Client::0_90::Direct' }; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
subtype ES(), as ES_1x | ES_90; |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
coerce ES, from HashRef, |
83
|
|
|
|
|
|
|
via { Search::Elasticsearch->new( { client => '1_0::Direct', %$_ } ) }; |
84
|
|
|
|
|
|
|
coerce ES, from Str, via { |
85
|
|
|
|
|
|
|
s/^:/127.0.0.1:/; |
86
|
|
|
|
|
|
|
Search::Elasticsearch->new( client => '1_0::Direct', nodes => $_ ); |
87
|
|
|
|
|
|
|
}; |
88
|
|
|
|
|
|
|
coerce ES, from ArrayRef, via { |
89
|
|
|
|
|
|
|
my @nodes = @$_; |
90
|
|
|
|
|
|
|
s/^:/127.0.0.1:/ for @nodes; |
91
|
|
|
|
|
|
|
Search::Elasticsearch->new( client => '1_0::Direct', nodes => \@nodes ); |
92
|
|
|
|
|
|
|
}; |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
subtype StoreMapping, as enum( [ 'yes', 'no' ] ); |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
coerce StoreMapping, from Any, via { $_ ? 'yes' : 'no' }; |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
subtype MultiField, as Dict [ |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
type => Optional [CoreFieldType], |
103
|
|
|
|
|
|
|
index => Optional [IndexMapping], |
104
|
|
|
|
|
|
|
index_name => Optional [Str], |
105
|
|
|
|
|
|
|
boost => Optional [Num], |
106
|
|
|
|
|
|
|
null_value => Optional [Str], |
107
|
|
|
|
|
|
|
analyzer => Optional [Str], |
108
|
|
|
|
|
|
|
index_analyzer => Optional [Str], |
109
|
|
|
|
|
|
|
search_analyzer => Optional [Str], |
110
|
|
|
|
|
|
|
search_quote_analyzer => Optional [Str], |
111
|
|
|
|
|
|
|
term_vector => Optional [TermVectorMapping], |
112
|
|
|
|
|
|
|
geohash => Optional [Bool], |
113
|
|
|
|
|
|
|
lat_lon => Optional [Bool], |
114
|
|
|
|
|
|
|
geohash_precision => Optional [Int], |
115
|
|
|
|
|
|
|
precision_step => Optional [Int], |
116
|
|
|
|
|
|
|
format => Optional [Str], |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
]; |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
subtype MultiFields, as HashRef [MultiField]; |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
subtype SortArgs, as ArrayRef; |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
coerce SortArgs, from HashRef, via { [$_] }; |
128
|
|
|
|
|
|
|
coerce SortArgs, from Str, via { [$_] }; |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
subtype HighlightArgs, as HashRef; |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
coerce HighlightArgs, from Str, via { return { $_ => {} } }; |
134
|
|
|
|
|
|
|
coerce HighlightArgs, from ArrayRef, via { |
135
|
|
|
|
|
|
|
my $args = $_; |
136
|
|
|
|
|
|
|
my %fields; |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
while ( my $field = shift @$args ) { |
139
|
|
|
|
|
|
|
die "Expected a field name but got ($field)" |
140
|
|
|
|
|
|
|
if ref $field; |
141
|
|
|
|
|
|
|
$fields{$field} = ref $args->[0] eq 'HASH' ? shift @$args : {}; |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
return \%fields; |
144
|
|
|
|
|
|
|
}; |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
subtype Longitude, as Num, |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
where { $_ >= -180 and $_ <= 180 }, |
150
|
|
|
|
|
|
|
message {"Longitude must be in the range -180 to 180"}; |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
subtype Latitude, as Num, |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
where { $_ >= -90 and $_ <= 90 }, |
156
|
|
|
|
|
|
|
message {"Latitude must be in the range -90 to 90"}; |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
subtype GeoPoint, as Dict [ lat => Latitude, lon => Longitude ]; |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
coerce GeoPoint, from ArrayRef, via { { lon => $_->[0], lat => $_->[1] } }; |
162
|
|
|
|
|
|
|
coerce GeoPoint, from Str, via { |
163
|
|
|
|
|
|
|
my ( $lat, $lon ) = split /,/; |
164
|
|
|
|
|
|
|
{ lon => $lon, lat => $lat }; |
165
|
|
|
|
|
|
|
}; |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
subtype Binary, as Defined; |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
subtype IndexNames, as ArrayRef [Str], |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
where { @{$_} > 0 }, |
175
|
|
|
|
|
|
|
message {"At least one domain name is required"}; |
176
|
|
|
|
|
|
|
coerce IndexNames, from Str, via { [$_] }; |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
subtype ArrayRefOfStr, as ArrayRef [Str]; |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
coerce ArrayRefOfStr, from Str, via { [$_] }; |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
subtype Timestamp, as Num; |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
subtype Keyword, as Str; |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
class_type UID, { class => 'Elastic::Model::UID' }; |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
coerce UID, from Str, via { Elastic::Model::UID->new_from_string($_) }; |
195
|
|
|
|
|
|
|
coerce UID, from HashRef, via { Elastic::Model::UID->new($_) }; |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
1; |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
=pod |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
=encoding UTF-8 |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
=head1 NAME |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
Elastic::Model::Types - MooseX::Types for general and internal use |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
=head1 VERSION |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
version 0.52 |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
=head1 SYNOPSIS |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
use Elastic::Model::Types qw(GeoPoint); |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
has 'point' => ( |
216
|
|
|
|
|
|
|
is => 'ro', |
217
|
|
|
|
|
|
|
isa => GeoPoint, |
218
|
|
|
|
|
|
|
coerce => 1 |
219
|
|
|
|
|
|
|
); |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
=head1 DESCRIPTION |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
Elastic::Model::Types define a number of L<MooseX::Types>, some for internal |
224
|
|
|
|
|
|
|
use and some which will be useful generally. |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
=head1 PUBLIC TYPES |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
=head2 Keyword |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
use Elastic::Model::Types qw(Keyword); |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
has 'status' => ( |
233
|
|
|
|
|
|
|
is => 'ro', |
234
|
|
|
|
|
|
|
isa => Keyword |
235
|
|
|
|
|
|
|
); |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
C<Keyword> is a sub-type of C<Str>. It is provided to make it easy to map |
238
|
|
|
|
|
|
|
string values which should not be analyzed (eg a C<status> field rather than |
239
|
|
|
|
|
|
|
a C<comment_body> field). See L<Elastic::Model::TypeMap::ES/Keyword>. |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
=head2 Binary |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
use Elastic::Model::Types qw(Binary); |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
has 'binary_field' => ( |
246
|
|
|
|
|
|
|
is => 'ro', |
247
|
|
|
|
|
|
|
isa => Binary |
248
|
|
|
|
|
|
|
); |
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
Inherits from the C<Defined> type. Is automatically Base64 encoded/decoded. |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
=head2 GeoPoint |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
use Elastic::Model::Types qw(GeoPoint); |
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
has 'point' => ( |
257
|
|
|
|
|
|
|
is => 'ro', |
258
|
|
|
|
|
|
|
isa => GeoPoint, |
259
|
|
|
|
|
|
|
coerce => 1, |
260
|
|
|
|
|
|
|
); |
261
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
C<GeoPoint> is a hashref with two keys: |
263
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
=over |
265
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
=item * |
267
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
C<lon>: a C<Number> between -180 and 180 |
269
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
=item * |
271
|
|
|
|
|
|
|
|
272
|
|
|
|
|
|
|
C<lat>: a C<Number> between -90 and 90 |
273
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
=back |
275
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
It can be coerced from an C<ArrayRef> with C<[$lon,$lat]> and from a |
277
|
|
|
|
|
|
|
C<Str> with C<"$lat,$lon">. |
278
|
|
|
|
|
|
|
|
279
|
|
|
|
|
|
|
=head2 Timestamp |
280
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
use Elastic::Model::Types qw(Timestamp); |
282
|
|
|
|
|
|
|
|
283
|
|
|
|
|
|
|
has 'timestamp' => ( |
284
|
|
|
|
|
|
|
is => 'ro', |
285
|
|
|
|
|
|
|
isa => Timestamp |
286
|
|
|
|
|
|
|
); |
287
|
|
|
|
|
|
|
|
288
|
|
|
|
|
|
|
A C<Timestamp> is a C<Num> which holds floating point epoch seconds, with milliseconds resolution. |
289
|
|
|
|
|
|
|
It is automatically mapped as a C<date> field in Elasticsearch. |
290
|
|
|
|
|
|
|
|
291
|
|
|
|
|
|
|
=head1 AUTHOR |
292
|
|
|
|
|
|
|
|
293
|
|
|
|
|
|
|
Clinton Gormley <drtech@cpan.org> |
294
|
|
|
|
|
|
|
|
295
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
296
|
|
|
|
|
|
|
|
297
|
|
|
|
|
|
|
This software is copyright (c) 2015 by Clinton Gormley. |
298
|
|
|
|
|
|
|
|
299
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
300
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
301
|
|
|
|
|
|
|
|
302
|
|
|
|
|
|
|
=cut |
303
|
|
|
|
|
|
|
|
304
|
|
|
|
|
|
|
__END__ |
305
|
|
|
|
|
|
|
|
306
|
|
|
|
|
|
|
# ABSTRACT: MooseX::Types for general and internal use |
307
|
|
|
|
|
|
|
|
308
|
|
|
|
|
|
|
|