| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Elastic::Model::Alias; |
|
2
|
|
|
|
|
|
|
$Elastic::Model::Alias::VERSION = '0.51'; |
|
3
|
23
|
|
|
23
|
|
153
|
use Carp; |
|
|
23
|
|
|
|
|
37
|
|
|
|
23
|
|
|
|
|
1870
|
|
|
4
|
23
|
|
|
23
|
|
131
|
use Moose; |
|
|
23
|
|
|
|
|
37
|
|
|
|
23
|
|
|
|
|
176
|
|
|
5
|
|
|
|
|
|
|
with 'Elastic::Model::Role::Index'; |
|
6
|
|
|
|
|
|
|
|
|
7
|
23
|
|
|
23
|
|
135436
|
use namespace::autoclean; |
|
|
23
|
|
|
|
|
56
|
|
|
|
23
|
|
|
|
|
248
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
23
|
|
|
23
|
|
2255
|
no Moose; |
|
|
23
|
|
|
|
|
44
|
|
|
|
23
|
|
|
|
|
133
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub to { |
|
13
|
|
|
|
|
|
|
|
|
14
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
15
|
|
|
|
|
|
|
|
|
16
|
0
|
|
|
|
|
|
my $name = $self->name; |
|
17
|
0
|
|
|
|
|
|
my $store = $self->model->store; |
|
18
|
0
|
|
|
|
|
|
my %indices = ( |
|
19
|
0
|
|
|
|
|
|
( map { $_ => { remove => { index => $_, alias => $name } } } |
|
20
|
0
|
|
|
|
|
|
keys %{ $store->get_aliases( index => $name ) } |
|
21
|
|
|
|
|
|
|
), |
|
22
|
|
|
|
|
|
|
$self->_add_aliases(@_) |
|
23
|
|
|
|
|
|
|
); |
|
24
|
|
|
|
|
|
|
|
|
25
|
0
|
|
|
|
|
|
$store->put_aliases( actions => [ values %indices ] ); |
|
26
|
0
|
|
|
|
|
|
$self->model->domain($name)->clear_default_routing; |
|
27
|
0
|
|
|
|
|
|
$self->model->clear_domain_namespace; |
|
28
|
0
|
|
|
|
|
|
return $self; |
|
29
|
|
|
|
|
|
|
} |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub add { |
|
33
|
|
|
|
|
|
|
|
|
34
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
35
|
0
|
|
|
|
|
|
my %indices = $self->_add_aliases(@_); |
|
36
|
0
|
|
|
|
|
|
$self->model->store->put_aliases( actions => [ values %indices ] ); |
|
37
|
0
|
|
|
|
|
|
$self->model->domain( $self->name )->clear_default_routing; |
|
38
|
0
|
|
|
|
|
|
return $self; |
|
39
|
|
|
|
|
|
|
} |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub remove { |
|
43
|
|
|
|
|
|
|
|
|
44
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
45
|
0
|
|
|
|
|
|
my $name = $self->name; |
|
46
|
0
|
|
|
|
|
|
my @actions = map { { remove => { index => $_, alias => $name } } } @_; |
|
|
0
|
|
|
|
|
|
|
|
47
|
0
|
|
|
|
|
|
$self->model->store->put_aliases( actions => \@actions ); |
|
48
|
0
|
|
|
|
|
|
$self->model->clear_domain_namespace; |
|
49
|
0
|
|
|
|
|
|
return $self; |
|
50
|
|
|
|
|
|
|
} |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub aliased_to { |
|
54
|
|
|
|
|
|
|
|
|
55
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
56
|
0
|
|
|
|
|
|
my $name = $self->name; |
|
57
|
|
|
|
|
|
|
|
|
58
|
0
|
|
|
|
|
|
my $indices = $self->model->store->get_aliases( index => $name ); |
|
59
|
0
|
0
|
|
|
|
|
croak "($name) is an index, not an alias" |
|
60
|
|
|
|
|
|
|
if $indices->{$name}; |
|
61
|
|
|
|
|
|
|
|
|
62
|
0
|
|
|
|
|
|
+{ map { $_ => $indices->{$_}{aliases}{$name} } keys %$indices }; |
|
|
0
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
} |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub _add_aliases { |
|
67
|
|
|
|
|
|
|
|
|
68
|
0
|
|
|
0
|
|
|
my $self = shift; |
|
69
|
0
|
|
|
|
|
|
my $name = $self->name; |
|
70
|
0
|
|
|
|
|
|
my $store = $self->model->store; |
|
71
|
0
|
|
|
|
|
|
my %indices; |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
my $builder; |
|
74
|
0
|
|
|
|
|
|
while (@_) { |
|
75
|
0
|
|
|
|
|
|
my $index = shift @_; |
|
76
|
0
|
|
|
|
|
|
my %params = ( |
|
77
|
0
|
0
|
|
|
|
|
ref $_[0] ? %{ shift @_ } : (), |
|
78
|
|
|
|
|
|
|
index => $index, |
|
79
|
|
|
|
|
|
|
alias => $name |
|
80
|
|
|
|
|
|
|
); |
|
81
|
0
|
0
|
|
|
|
|
if ( my $filter = delete $params{filterb} ) { |
|
82
|
0
|
|
0
|
|
|
|
$builder ||= $self->model->view->search_builder; |
|
83
|
0
|
|
|
|
|
|
$params{filter} = $builder->filter($filter)->{filter}; |
|
84
|
|
|
|
|
|
|
} |
|
85
|
0
|
|
|
|
|
|
$indices{$index} = { add => \%params }; |
|
86
|
|
|
|
|
|
|
} |
|
87
|
0
|
|
|
|
|
|
return %indices; |
|
88
|
|
|
|
|
|
|
} |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
1; |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=pod |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=encoding UTF-8 |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head1 NAME |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
Elastic::Model::Alias - Administer aliases in Elasticsearch |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head1 VERSION |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
version 0.51 |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
$alias = $model->namespace('myapp')->alias; |
|
109
|
|
|
|
|
|
|
$alias = $model->namespace('myapp')->alias('alias_name'); |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
$alias->to( 'index_1', 'index_2' ); |
|
112
|
|
|
|
|
|
|
$alias->to( 'index_1' => \%settings, index_2 => \%settings); |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
$alias->add( 'index_1', 'index_2' ); |
|
115
|
|
|
|
|
|
|
$alias->add( 'index_1' => \%settings, index_2 => \%settings); |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
$alias->remove( 'index_1', 'index_2' ); |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
\%indices = $alias->aliased_to; |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
See also L<Elastic::Model::Role::Index/SYNOPSIS>. |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
L<Elastic::Model::Alias> objects are used to create and administer |
|
126
|
|
|
|
|
|
|
L<index aliases|Elastic::Manual::Terminology/Alias> in an Elasticsearch cluster. |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
See L<Elastic::Model::Role::Index> for more about usage. |
|
129
|
|
|
|
|
|
|
See L<Elastic::Manual::Scaling> for more about how aliases can be used in your |
|
130
|
|
|
|
|
|
|
application. |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head1 METHODS |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head2 to() |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
$alias = $alias->to(@index_names); |
|
137
|
|
|
|
|
|
|
$alias = $alias->to( |
|
138
|
|
|
|
|
|
|
index_name => \%alias_settings, |
|
139
|
|
|
|
|
|
|
... |
|
140
|
|
|
|
|
|
|
); |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
Creates or updates the alias L</name> and sets it to point |
|
143
|
|
|
|
|
|
|
to the listed indices. If it already exists and points to indices not specified |
|
144
|
|
|
|
|
|
|
in C<@index_names>, then those indices will be removed from the alias. |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
You can delete an alias completely with: |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
$alias->to(); |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
Aliases can have filters and routing values associated with an index, for |
|
151
|
|
|
|
|
|
|
instance: |
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
$alias->to( |
|
154
|
|
|
|
|
|
|
my_index => { |
|
155
|
|
|
|
|
|
|
routing => 'client_one', |
|
156
|
|
|
|
|
|
|
filterb => { client => 'client_one'} |
|
157
|
|
|
|
|
|
|
} |
|
158
|
|
|
|
|
|
|
); |
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
See L<Elastic::Manual::Scaling> for more about these options. |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=head2 add() |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
$alias = $alias->add(@index_names); |
|
165
|
|
|
|
|
|
|
$alias = $alias->add( |
|
166
|
|
|
|
|
|
|
index_name => \%alias_settings, |
|
167
|
|
|
|
|
|
|
... |
|
168
|
|
|
|
|
|
|
); |
|
169
|
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
L</add()> works in the same way as L</to()> except that |
|
171
|
|
|
|
|
|
|
indices are only added - existing indices are not removed. |
|
172
|
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=head2 remove() |
|
174
|
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
$alias = $alias->remove(@index_names); |
|
176
|
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
The listed index names are removed from alias L</name>. |
|
178
|
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=head2 aliased_to() |
|
180
|
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
$indices = $alias->aliased_to(); |
|
182
|
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
Returns a hashref of the current settings for an alias, suitable for passing to |
|
184
|
|
|
|
|
|
|
L</to()>. The keys are index names, and the values are the alias settings. |
|
185
|
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=head1 IMPORTED ATTRIBUTES |
|
187
|
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
Attributes imported from L<Elastic::Model::Role::Index> |
|
189
|
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=head2 L<namespace|Elastic::Model::Role::Index/namespace> |
|
191
|
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=head2 L<name|Elastic::Model::Role::Index/name> |
|
193
|
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=head1 IMPORTED METHODS |
|
195
|
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
Methods imported from L<Elastic::Model::Role::Index> |
|
197
|
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
=head2 L<close()|Elastic::Model::Role::Index/close()> |
|
199
|
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
=head2 L<open()|Elastic::Model::Role::Index/open()> |
|
201
|
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
=head2 L<refresh()|Elastic::Model::Role::Index/refresh()> |
|
203
|
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
=head2 L<delete()|Elastic::Model::Role::Index/delete()> |
|
205
|
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
=head2 L<update_analyzers()|Elastic::Model::Role::Index/update_analyzers()> |
|
207
|
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
=head2 L<update_settings()|Elastic::Model::Role::Index/update_settings()> |
|
209
|
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
=head2 L<delete_mapping()|Elastic::Model::Role::Index/delete_mapping()> |
|
211
|
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
=head2 L<is_alias()|Elastic::Model::Role::Index/is_alias()> |
|
213
|
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
=head2 L<is_index()|Elastic::Model::Role::Index/is_index()> |
|
215
|
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
217
|
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
=over |
|
219
|
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
=item * |
|
221
|
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
L<Elastic::Model::Role::Index> |
|
223
|
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
=item * |
|
225
|
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
L<Elastic::Model::Index> |
|
227
|
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
=item * |
|
229
|
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
L<Elastic::Model::Namespace> |
|
231
|
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
=item * |
|
233
|
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
L<Elastic::Manual::Scaling> |
|
235
|
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
=back |
|
237
|
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
=head1 AUTHOR |
|
239
|
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
Clinton Gormley <drtech@cpan.org> |
|
241
|
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
243
|
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
This software is copyright (c) 2015 by Clinton Gormley. |
|
245
|
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
|
247
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
|
248
|
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
=cut |
|
250
|
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
__END__ |
|
252
|
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
# ABSTRACT: Administer aliases in Elasticsearch |
|
254
|
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
|