line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Elasticsearch; |
2
|
|
|
|
|
|
|
|
3
|
50
|
|
|
50
|
|
2328551
|
use Moo 1.003; |
|
50
|
|
|
|
|
1392464
|
|
|
50
|
|
|
|
|
399
|
|
4
|
|
|
|
|
|
|
|
5
|
50
|
|
|
50
|
|
151123
|
use Elasticsearch::Util qw(parse_params load_plugin); |
|
50
|
|
|
|
|
332
|
|
|
50
|
|
|
|
|
417
|
|
6
|
50
|
|
|
50
|
|
70927
|
use namespace::clean; |
|
50
|
|
|
|
|
920566
|
|
|
50
|
|
|
|
|
384
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '1.05'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
my %Default_Plugins = ( |
11
|
|
|
|
|
|
|
client => [ 'Elasticsearch::Client', 'Direct' ], |
12
|
|
|
|
|
|
|
cxn_factory => [ 'Elasticsearch::Cxn::Factory', '' ], |
13
|
|
|
|
|
|
|
cxn_pool => [ 'Elasticsearch::CxnPool', 'Static' ], |
14
|
|
|
|
|
|
|
logger => [ 'Elasticsearch::Logger', 'LogAny' ], |
15
|
|
|
|
|
|
|
serializer => [ 'Elasticsearch::Serializer', 'JSON' ], |
16
|
|
|
|
|
|
|
transport => [ 'Elasticsearch::Transport', '' ], |
17
|
|
|
|
|
|
|
); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
my @Load_Order = qw( |
20
|
|
|
|
|
|
|
serializer |
21
|
|
|
|
|
|
|
logger |
22
|
|
|
|
|
|
|
cxn_factory |
23
|
|
|
|
|
|
|
cxn_pool |
24
|
|
|
|
|
|
|
transport |
25
|
|
|
|
|
|
|
client |
26
|
|
|
|
|
|
|
); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
#=================================== |
29
|
|
|
|
|
|
|
sub new { |
30
|
|
|
|
|
|
|
#=================================== |
31
|
71
|
|
|
71
|
0
|
117100
|
my ( $class, $params ) = parse_params(@_); |
32
|
|
|
|
|
|
|
|
33
|
71
|
|
100
|
|
|
509
|
$params->{cxn} ||= 'HTTPTiny'; |
34
|
|
|
|
|
|
|
|
35
|
71
|
|
|
|
|
230
|
for my $name (@Load_Order) { |
36
|
426
|
|
|
|
|
156708
|
my ( $base, $default ) = @{ $Default_Plugins{$name} }; |
|
426
|
|
|
|
|
2048
|
|
37
|
426
|
|
100
|
|
|
2747
|
my $sub_class = $params->{$name} || $default; |
38
|
426
|
|
|
|
|
4096
|
my $plugin_class = load_plugin( $base, $sub_class ); |
39
|
426
|
|
|
|
|
14992
|
$params->{$name} = $plugin_class->new($params); |
40
|
|
|
|
|
|
|
} |
41
|
71
|
|
|
|
|
102083
|
return $params->{client}; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
package # hide from pause |
45
|
|
|
|
|
|
|
ElasticSearch::Deprecation; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub new { |
48
|
0
|
|
|
0
|
|
|
my $class = shift; |
49
|
0
|
|
|
|
|
|
die <<DEPRECATION; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
It appears that you are using a case-insensitive filesystem. You tried |
52
|
|
|
|
|
|
|
to load "ElasticSearch", but you have loaded "Elasticsearch" instead. See: |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
https://metacpan.org/release/Elasticsearch |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
ElasticSearch has been replaced by the official client: Elasticsearch. |
57
|
|
|
|
|
|
|
To ease your transition from old to new, please install Elasticsearch::Compat: |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
https://metacpan.org/module/Elasticsearch::Compat |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
DEPRECATION |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
@ElasticSearch::ISA = 'ElasticSearch::Deprecation'; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
1; |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=pod |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=encoding UTF-8 |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head1 NAME |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
Elasticsearch - DEPRECATED: The official client for Elasticsearch |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head1 VERSION |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
version 1.05 |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head1 DESCRIPTION |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
B<THIS MODULE IS DEPRECATED.> |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
****************************************************************************** |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
Because of the name clash between C<ElasticSearch.pm> and C<Elasticsearch.pm> |
87
|
|
|
|
|
|
|
the official Perl client is now called: L<Search::Elasticsearch>. |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
See L<https://github.com/elasticsearch/elasticsearch-perl/issues/20> for details. |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
This distribution will be removed from CPAN in 2015. Please update your code. |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
****************************************************************************** |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
L<Elasticsearch> is the official Perl client for Elasticsearch, supported |
96
|
|
|
|
|
|
|
by L<elasticsearch.com|http://www.elasticsearch.com>. Elasticsearch |
97
|
|
|
|
|
|
|
itself is a flexible and powerful open source, distributed real-time |
98
|
|
|
|
|
|
|
search and analytics engine for the cloud. You can read more about it |
99
|
|
|
|
|
|
|
on L<elasticsearch.org|http://www.elasticsearch.org>. |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head1 BACKWARDS COMPATIBILITY AND ELASTICSEARCH 0.90.x |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
This version of the client supports the Elasticsearch 1.0 branch by |
104
|
|
|
|
|
|
|
default, which is not backwards compatible with the 0.90 branch. |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
If you need to talk to a version of Elasticsearch before 1.0.0, |
107
|
|
|
|
|
|
|
please use L<Elasticsearch::Client::0_90::Direct> as follows: |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
$es = Elasticsearch->new( client => '0_90::Direct' ); |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=head2 Motivation |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=over |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
I<The greatest deception men suffer is from their own opinions.> |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
Leonardo da Vinci |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=back |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
All of us have opinions, especially when it comes to designing APIs. |
122
|
|
|
|
|
|
|
Unfortunately, the opinions of programmers seldom coincide. The intention of |
123
|
|
|
|
|
|
|
this client, and of the officially supported clients available for other |
124
|
|
|
|
|
|
|
languages, is to provide robust support for the full native Elasticsearch API |
125
|
|
|
|
|
|
|
with as few opinions as possible: you should be able to read the |
126
|
|
|
|
|
|
|
L<Elasticsearch reference documentation|http://www.elasticsearch.org/guide> |
127
|
|
|
|
|
|
|
and understand how to use this client, or any of the other official clients. |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
Should you decide that you want to customize the API, then this client |
130
|
|
|
|
|
|
|
provides the basis for your code. It does the hard stuff for you, |
131
|
|
|
|
|
|
|
allowing you to build on top of it. |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head2 Features |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
This client provides: |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=over |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=item * |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
Full support for all Elasticsearch APIs |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=item * |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
HTTP backend (currently synchronous only - L<Any::Event> support will be added |
146
|
|
|
|
|
|
|
later) |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=item * |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
Robust networking support which handles load balancing, failure detection |
151
|
|
|
|
|
|
|
and failover |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=item * |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
Good defaults |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=item * |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
Helper utilities for more complex operations, such as |
160
|
|
|
|
|
|
|
L<bulk indexing|Elasticsearch::Bulk>, |
161
|
|
|
|
|
|
|
L<scrolled searches|Elasticsearch::Scroll> and |
162
|
|
|
|
|
|
|
L<reindexing|Elasticsearch::Bulk/"reindex()">. |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=item * |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
Logging support via L<Log::Any> |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=item * |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
Compatibility with the official clients for Python, Ruby, PHP and Javascript |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=item * |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
Easy extensibility |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=back |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=head1 INSTALLING ELASTICSEARCH |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
You can download the latest version of Elasticsearch from |
181
|
|
|
|
|
|
|
L<http://www.elasticsearch.org/download>. See the |
182
|
|
|
|
|
|
|
L<installation instructions|http://www.elasticsearch.org/guide/reference/setup/installation/> |
183
|
|
|
|
|
|
|
for details. You will need to have a recent version of Java installed, |
184
|
|
|
|
|
|
|
preferably the Java v7 from Sun. |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=head1 CREATING A NEW INSTANCE |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
The L</new()> method returns a new L<client|Elasticsearch::Client::Direct> |
189
|
|
|
|
|
|
|
which can be used to run requests against the Elasticsearch cluster. |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
use Elasticsearch; |
192
|
|
|
|
|
|
|
my $e = Elasticsearch->new( %params ); |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
The most important arguments to L</new()> are the following: |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
=head2 C<nodes> |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
The C<nodes> parameter tells the client which Elasticsearch nodes it should |
199
|
|
|
|
|
|
|
talk to. It can be a single node, multiples nodes or, if not |
200
|
|
|
|
|
|
|
specified, will default to C<localhost:9200>: |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
# default: localhost:9200 |
203
|
|
|
|
|
|
|
$e = Elasticsearch->new(); |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
# single |
206
|
|
|
|
|
|
|
$e = Elasticsearch->new( nodes => 'search_1:9200'); |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
# multiple |
209
|
|
|
|
|
|
|
$e = Elasticsearch->new( |
210
|
|
|
|
|
|
|
nodes => [ |
211
|
|
|
|
|
|
|
'search_1:9200', |
212
|
|
|
|
|
|
|
'search_2:9200' |
213
|
|
|
|
|
|
|
] |
214
|
|
|
|
|
|
|
); |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
Each C<node> can be a URL including a scheme, host, port, path and userinfo |
217
|
|
|
|
|
|
|
(for authentication). For instance, this would be a valid node: |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
https://username:password@search.domain.com:443/prefix/path |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
See L<Elasticsearch::Role::Cxn::HTTP/node> for more on node specification. |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
=head2 C<cxn_pool> |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
The L<CxnPool|Elasticsearch::Role::CxnPool> modules manage connections to |
226
|
|
|
|
|
|
|
nodes in the Elasticsearch cluster. They handle the load balancing between |
227
|
|
|
|
|
|
|
nodes and failover when nodes fail. Which C<CxnPool> you should use depends on |
228
|
|
|
|
|
|
|
where your cluster is. There are three choices: |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
=over |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
=item * C<Static> |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
$e = Elasticsearch->new( |
235
|
|
|
|
|
|
|
cxn_pool => 'Static' # default |
236
|
|
|
|
|
|
|
nodes => [ |
237
|
|
|
|
|
|
|
'search1.domain.com:9200', |
238
|
|
|
|
|
|
|
'search2.domain.com:9200' |
239
|
|
|
|
|
|
|
], |
240
|
|
|
|
|
|
|
); |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
The L<Static|Elasticsearch::CxnPool::Static> connection pool, which is the |
243
|
|
|
|
|
|
|
default, should be used when you don't have direct access to the Elasticsearch |
244
|
|
|
|
|
|
|
cluster, eg when you are accessing the cluster through a proxy. See |
245
|
|
|
|
|
|
|
L<Elasticsearch::CxnPool::Static> for more. |
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
=item * C<Sniff> |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
$e = Elasticsearch->new( |
250
|
|
|
|
|
|
|
cxn_pool => 'Sniff', |
251
|
|
|
|
|
|
|
nodes => [ |
252
|
|
|
|
|
|
|
'search1:9200', |
253
|
|
|
|
|
|
|
'search2:9200' |
254
|
|
|
|
|
|
|
], |
255
|
|
|
|
|
|
|
); |
256
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
The L<Sniff|Elasticsearch::CxnPool::Sniff> connection pool should be used |
258
|
|
|
|
|
|
|
when you B<do> have direct access to the Elasticsearch cluster, eg when |
259
|
|
|
|
|
|
|
your web servers and Elasticsearch servers are on the same network. |
260
|
|
|
|
|
|
|
The nodes that you specify are used to I<discover> the cluster, which is |
261
|
|
|
|
|
|
|
then I<sniffed> to find the current list of live nodes that the cluster |
262
|
|
|
|
|
|
|
knows about. See L<Elasticsearch::CxnPool::Sniff>. |
263
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
=item * C<Static::NoPing> |
265
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
$e = Elasticsearch->new( |
267
|
|
|
|
|
|
|
cxn_pool => 'Static::NoPing' |
268
|
|
|
|
|
|
|
nodes => [ |
269
|
|
|
|
|
|
|
'proxy1.domain.com:80', |
270
|
|
|
|
|
|
|
'proxy2.domain.com:80' |
271
|
|
|
|
|
|
|
], |
272
|
|
|
|
|
|
|
); |
273
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
The L<Static::NoPing|Elasticsearch::CxnPool::Static::NoPing> connection |
275
|
|
|
|
|
|
|
pool should be used when your access to a remote cluster is so limited |
276
|
|
|
|
|
|
|
that you cannot ping individual nodes with a C<HEAD /> request. |
277
|
|
|
|
|
|
|
|
278
|
|
|
|
|
|
|
See L<Elasticsearch::CxnPool::Static::NoPing> for more. |
279
|
|
|
|
|
|
|
|
280
|
|
|
|
|
|
|
=back |
281
|
|
|
|
|
|
|
|
282
|
|
|
|
|
|
|
=head2 C<trace_to> |
283
|
|
|
|
|
|
|
|
284
|
|
|
|
|
|
|
For debugging purposes, it is useful to be able to dump the actual HTTP |
285
|
|
|
|
|
|
|
requests which are sent to the cluster, and the response that is received. |
286
|
|
|
|
|
|
|
This can be enabled with the C<trace_to> parameter, as follows: |
287
|
|
|
|
|
|
|
|
288
|
|
|
|
|
|
|
# To STDERR |
289
|
|
|
|
|
|
|
$e = Elasticsearch->new( |
290
|
|
|
|
|
|
|
trace_to => 'Stderr' |
291
|
|
|
|
|
|
|
); |
292
|
|
|
|
|
|
|
|
293
|
|
|
|
|
|
|
# To a file |
294
|
|
|
|
|
|
|
$e = Elasticsearch->new( |
295
|
|
|
|
|
|
|
trace_to => ['File','/path/to/filename'] |
296
|
|
|
|
|
|
|
); |
297
|
|
|
|
|
|
|
|
298
|
|
|
|
|
|
|
Logging is handled by L<Log::Any>. See L<Elasticsearch::Logger::LogAny> |
299
|
|
|
|
|
|
|
for more information. |
300
|
|
|
|
|
|
|
|
301
|
|
|
|
|
|
|
=head2 Other |
302
|
|
|
|
|
|
|
|
303
|
|
|
|
|
|
|
Other arguments are explained in the respective L<module docs|/MODULES>. |
304
|
|
|
|
|
|
|
|
305
|
|
|
|
|
|
|
=head1 RUNNING REQUESTS |
306
|
|
|
|
|
|
|
|
307
|
|
|
|
|
|
|
When you create a new instance of Elasticsearch, it returns a |
308
|
|
|
|
|
|
|
L<client|Elasticsearch::Client::Direct> object, which can be used for |
309
|
|
|
|
|
|
|
running requests. |
310
|
|
|
|
|
|
|
|
311
|
|
|
|
|
|
|
use Elasticsearch; |
312
|
|
|
|
|
|
|
my $e = Elasticsearch->new( %params ); |
313
|
|
|
|
|
|
|
|
314
|
|
|
|
|
|
|
# create an index |
315
|
|
|
|
|
|
|
$e->indices->create( index => 'my_index' ); |
316
|
|
|
|
|
|
|
|
317
|
|
|
|
|
|
|
# index a document |
318
|
|
|
|
|
|
|
$e->index( |
319
|
|
|
|
|
|
|
index => 'my_index', |
320
|
|
|
|
|
|
|
type => 'blog_post', |
321
|
|
|
|
|
|
|
id => 1, |
322
|
|
|
|
|
|
|
body => { |
323
|
|
|
|
|
|
|
title => 'Elasticsearch clients', |
324
|
|
|
|
|
|
|
content => 'Interesting content...', |
325
|
|
|
|
|
|
|
date => '2013-09-24' |
326
|
|
|
|
|
|
|
} |
327
|
|
|
|
|
|
|
); |
328
|
|
|
|
|
|
|
|
329
|
|
|
|
|
|
|
See L<Elasticsearch::Client::Direct> for more details about the requests that |
330
|
|
|
|
|
|
|
can be run. |
331
|
|
|
|
|
|
|
|
332
|
|
|
|
|
|
|
=head1 MODULES |
333
|
|
|
|
|
|
|
|
334
|
|
|
|
|
|
|
Each chunk of functionality is handled by a different module, |
335
|
|
|
|
|
|
|
which can be specified in the call to L<new()> as shown in L<cxn_pool> above. |
336
|
|
|
|
|
|
|
For instance, the following will use the L<Elasticsearch::CxnPool::Sniff> |
337
|
|
|
|
|
|
|
module for the connection pool. |
338
|
|
|
|
|
|
|
|
339
|
|
|
|
|
|
|
$e = Elasticsearch->new( |
340
|
|
|
|
|
|
|
cxn_pool => 'Sniff' |
341
|
|
|
|
|
|
|
); |
342
|
|
|
|
|
|
|
|
343
|
|
|
|
|
|
|
Custom modules can be named with the appropriate prefix, |
344
|
|
|
|
|
|
|
eg C<Elasticsearch::CxnPool::>, or by prefixing the full class name |
345
|
|
|
|
|
|
|
with C<+>: |
346
|
|
|
|
|
|
|
|
347
|
|
|
|
|
|
|
$e = Elasticsearch->new( |
348
|
|
|
|
|
|
|
cxn_pool => '+My::Custom::CxnClass' |
349
|
|
|
|
|
|
|
); |
350
|
|
|
|
|
|
|
|
351
|
|
|
|
|
|
|
The modules that you can override are specified with the following |
352
|
|
|
|
|
|
|
arguments to L</new()>: |
353
|
|
|
|
|
|
|
|
354
|
|
|
|
|
|
|
=head2 C<client> |
355
|
|
|
|
|
|
|
|
356
|
|
|
|
|
|
|
The class to use for the client functionality, which provides |
357
|
|
|
|
|
|
|
methods that can be called to execute requests, such as |
358
|
|
|
|
|
|
|
C<search()>, C<index()> or C<delete()>. The client parses the user's |
359
|
|
|
|
|
|
|
requests and passes them to the L</transport> class to be executed. |
360
|
|
|
|
|
|
|
See : |
361
|
|
|
|
|
|
|
|
362
|
|
|
|
|
|
|
=over |
363
|
|
|
|
|
|
|
|
364
|
|
|
|
|
|
|
=item * L<Elasticsearch::Client::Direct> (default, for 1.0 branch) |
365
|
|
|
|
|
|
|
|
366
|
|
|
|
|
|
|
=item * L<Elasticsearch::Client::0_90::Direct> (for 0.90 branch) |
367
|
|
|
|
|
|
|
|
368
|
|
|
|
|
|
|
=item * L<Elasticsearch::Client::Compat> (for migration from the old |
369
|
|
|
|
|
|
|
L<ElasticSearch> module) |
370
|
|
|
|
|
|
|
|
371
|
|
|
|
|
|
|
=back |
372
|
|
|
|
|
|
|
|
373
|
|
|
|
|
|
|
=head2 C<transport> |
374
|
|
|
|
|
|
|
|
375
|
|
|
|
|
|
|
The Transport class accepts a parsed request from the L</client> class, |
376
|
|
|
|
|
|
|
fetches a L</cxn> from its L</cxn_pool> and tries to execute the request, |
377
|
|
|
|
|
|
|
retrying after failure where appropriate. See: |
378
|
|
|
|
|
|
|
|
379
|
|
|
|
|
|
|
=over |
380
|
|
|
|
|
|
|
|
381
|
|
|
|
|
|
|
=item * L<Elasticsearch::Transport> |
382
|
|
|
|
|
|
|
|
383
|
|
|
|
|
|
|
=back |
384
|
|
|
|
|
|
|
|
385
|
|
|
|
|
|
|
=head2 C<cxn> |
386
|
|
|
|
|
|
|
|
387
|
|
|
|
|
|
|
The class which handles raw requests to Elasticsearch nodes. |
388
|
|
|
|
|
|
|
See: |
389
|
|
|
|
|
|
|
|
390
|
|
|
|
|
|
|
=over |
391
|
|
|
|
|
|
|
|
392
|
|
|
|
|
|
|
=item * L<Elasticsearch::Cxn::HTTPTiny> (default) |
393
|
|
|
|
|
|
|
|
394
|
|
|
|
|
|
|
=item * L<Elasticsearch::Cxn::Hijk> |
395
|
|
|
|
|
|
|
|
396
|
|
|
|
|
|
|
=item * L<Elasticsearch::Cxn::LWP> |
397
|
|
|
|
|
|
|
|
398
|
|
|
|
|
|
|
=item * L<Elasticsearch::Cxn::NetCurl> |
399
|
|
|
|
|
|
|
|
400
|
|
|
|
|
|
|
=back |
401
|
|
|
|
|
|
|
|
402
|
|
|
|
|
|
|
=head2 C<cxn_factory> |
403
|
|
|
|
|
|
|
|
404
|
|
|
|
|
|
|
The class which the L</cxn_pool> uses to create new L</cxn> objects. |
405
|
|
|
|
|
|
|
See: |
406
|
|
|
|
|
|
|
|
407
|
|
|
|
|
|
|
=over |
408
|
|
|
|
|
|
|
|
409
|
|
|
|
|
|
|
=item * L<Elasticsearch::Cxn::Factory> |
410
|
|
|
|
|
|
|
|
411
|
|
|
|
|
|
|
=back |
412
|
|
|
|
|
|
|
|
413
|
|
|
|
|
|
|
=head2 C<cxn_pool> (2) |
414
|
|
|
|
|
|
|
|
415
|
|
|
|
|
|
|
The class to use for the L<connection pool|/cxn_pool> functionality. |
416
|
|
|
|
|
|
|
It calls the L</cxn_factory> class to create new L</cxn> objects when |
417
|
|
|
|
|
|
|
appropriate. See: |
418
|
|
|
|
|
|
|
|
419
|
|
|
|
|
|
|
=over |
420
|
|
|
|
|
|
|
|
421
|
|
|
|
|
|
|
=item * L<Elasticsearch::CxnPool::Static> (default) |
422
|
|
|
|
|
|
|
|
423
|
|
|
|
|
|
|
=item * L<Elasticsearch::CxnPool::Sniff> |
424
|
|
|
|
|
|
|
|
425
|
|
|
|
|
|
|
=item * L<Elasticsearch::CxnPool::Static::NoPing> |
426
|
|
|
|
|
|
|
|
427
|
|
|
|
|
|
|
=back |
428
|
|
|
|
|
|
|
|
429
|
|
|
|
|
|
|
=head2 C<logger> |
430
|
|
|
|
|
|
|
|
431
|
|
|
|
|
|
|
The class to use for logging events and tracing HTTP requests/responses. See: |
432
|
|
|
|
|
|
|
|
433
|
|
|
|
|
|
|
=over |
434
|
|
|
|
|
|
|
|
435
|
|
|
|
|
|
|
=item * L<Elasticsearch::Logger::LogAny> |
436
|
|
|
|
|
|
|
|
437
|
|
|
|
|
|
|
=back |
438
|
|
|
|
|
|
|
|
439
|
|
|
|
|
|
|
=head2 C<serializer> |
440
|
|
|
|
|
|
|
|
441
|
|
|
|
|
|
|
The class to use for serializing request bodies and deserializing response |
442
|
|
|
|
|
|
|
bodies. See: |
443
|
|
|
|
|
|
|
|
444
|
|
|
|
|
|
|
=over |
445
|
|
|
|
|
|
|
|
446
|
|
|
|
|
|
|
=item * L<Elasticsearch::Serializer::JSON> |
447
|
|
|
|
|
|
|
|
448
|
|
|
|
|
|
|
=back |
449
|
|
|
|
|
|
|
|
450
|
|
|
|
|
|
|
=head1 MIGRATING FROM ElasticSearch.pm |
451
|
|
|
|
|
|
|
|
452
|
|
|
|
|
|
|
See L<Elasticsearch::Compat>, which allows you to run your old |
453
|
|
|
|
|
|
|
L<ElasticSearch> code with the new L<Elasticsearch> module. |
454
|
|
|
|
|
|
|
|
455
|
|
|
|
|
|
|
The L<Elasticsearch> API is pretty similar to the old L<ElasticSearch> API, |
456
|
|
|
|
|
|
|
but there are a few differences. The most notable are: |
457
|
|
|
|
|
|
|
|
458
|
|
|
|
|
|
|
=head2 C<hosts> vs C<servers> |
459
|
|
|
|
|
|
|
|
460
|
|
|
|
|
|
|
When instantiating a new Elasticsearch instance, use C<nodes> instead of |
461
|
|
|
|
|
|
|
C<servers>: |
462
|
|
|
|
|
|
|
|
463
|
|
|
|
|
|
|
$e = Elasticsearch->new( |
464
|
|
|
|
|
|
|
nodes => [ 'search1:9200', 'search2:9200' ] |
465
|
|
|
|
|
|
|
); |
466
|
|
|
|
|
|
|
|
467
|
|
|
|
|
|
|
=head2 C<no_refresh> |
468
|
|
|
|
|
|
|
|
469
|
|
|
|
|
|
|
By default, the new client does not sniff the cluster to discover nodes. |
470
|
|
|
|
|
|
|
To enable sniffing, use: |
471
|
|
|
|
|
|
|
|
472
|
|
|
|
|
|
|
$e = Elasticsearch->new( |
473
|
|
|
|
|
|
|
cxn_pool => 'Sniff', |
474
|
|
|
|
|
|
|
nodes => [ 'search1:9200', 'search2:9200' ] |
475
|
|
|
|
|
|
|
); |
476
|
|
|
|
|
|
|
|
477
|
|
|
|
|
|
|
To disable sniffing (the equivalent of setting C<no_refresh> to C<true>), do: |
478
|
|
|
|
|
|
|
|
479
|
|
|
|
|
|
|
$e = Elasticsearch->new( |
480
|
|
|
|
|
|
|
nodes => [ 'search1:9200', 'search2:9200' ] |
481
|
|
|
|
|
|
|
); |
482
|
|
|
|
|
|
|
|
483
|
|
|
|
|
|
|
=head2 Request parameters |
484
|
|
|
|
|
|
|
|
485
|
|
|
|
|
|
|
In the old client, you could specify query string and body parameters at |
486
|
|
|
|
|
|
|
the same level, eg: |
487
|
|
|
|
|
|
|
|
488
|
|
|
|
|
|
|
$e->search( |
489
|
|
|
|
|
|
|
search_type => 'count', |
490
|
|
|
|
|
|
|
query => { |
491
|
|
|
|
|
|
|
match_all => {} |
492
|
|
|
|
|
|
|
} |
493
|
|
|
|
|
|
|
); |
494
|
|
|
|
|
|
|
|
495
|
|
|
|
|
|
|
In the new client, body parameters should be passed in a C<body> element: |
496
|
|
|
|
|
|
|
|
497
|
|
|
|
|
|
|
$e->search( |
498
|
|
|
|
|
|
|
search_type => 'count', |
499
|
|
|
|
|
|
|
body => { |
500
|
|
|
|
|
|
|
query => { |
501
|
|
|
|
|
|
|
match_all => {} |
502
|
|
|
|
|
|
|
} |
503
|
|
|
|
|
|
|
} |
504
|
|
|
|
|
|
|
); |
505
|
|
|
|
|
|
|
|
506
|
|
|
|
|
|
|
=head2 C<trace_calls> |
507
|
|
|
|
|
|
|
|
508
|
|
|
|
|
|
|
The new client uses L<Log::Any> for event logging and request tracing. |
509
|
|
|
|
|
|
|
To trace requests/responses in C<curl> format, do: |
510
|
|
|
|
|
|
|
|
511
|
|
|
|
|
|
|
# To STDERR |
512
|
|
|
|
|
|
|
$e = Elasticsearch->new (trace_to => 'Stderr'); |
513
|
|
|
|
|
|
|
|
514
|
|
|
|
|
|
|
# To a file |
515
|
|
|
|
|
|
|
$e = Elasticsearch->new (trace_to => ['File','/path/to/file.log']); |
516
|
|
|
|
|
|
|
|
517
|
|
|
|
|
|
|
=head2 SearchBuilder |
518
|
|
|
|
|
|
|
|
519
|
|
|
|
|
|
|
The old API integrated L<ElasticSearch::SearchBuilder> for an L<SQL::Abstract> |
520
|
|
|
|
|
|
|
style of writing queries and filters in Elasticsearch. |
521
|
|
|
|
|
|
|
This integration does not exist in the new client, but will be added in a |
522
|
|
|
|
|
|
|
future module. |
523
|
|
|
|
|
|
|
|
524
|
|
|
|
|
|
|
=head2 Bulk methods and C<scrolled_search()> |
525
|
|
|
|
|
|
|
|
526
|
|
|
|
|
|
|
Bulk indexing has changed a lot in the new client. The helper methods, eg |
527
|
|
|
|
|
|
|
C<bulk_index()> and C<reindex()> have been removed from the main client, |
528
|
|
|
|
|
|
|
and the C<bulk()> method itself now simply returns the response from |
529
|
|
|
|
|
|
|
Elasticsearch. It doesn't interfere with processing at all. |
530
|
|
|
|
|
|
|
|
531
|
|
|
|
|
|
|
These helper methods have been replaced by the L<Elasticsearch::Bulk> class. |
532
|
|
|
|
|
|
|
Similarly, C<scrolled_search()> has been replaced by the |
533
|
|
|
|
|
|
|
L<Elasticsearch::Scroll>. |
534
|
|
|
|
|
|
|
|
535
|
|
|
|
|
|
|
=head1 TODO |
536
|
|
|
|
|
|
|
|
537
|
|
|
|
|
|
|
=over |
538
|
|
|
|
|
|
|
|
539
|
|
|
|
|
|
|
=item * Async support |
540
|
|
|
|
|
|
|
|
541
|
|
|
|
|
|
|
Add async support using L<Promises> for L<AnyEvent> and perhaps L<Mojo>. |
542
|
|
|
|
|
|
|
|
543
|
|
|
|
|
|
|
=item * New frontend |
544
|
|
|
|
|
|
|
|
545
|
|
|
|
|
|
|
Add a new client with a similar less verbose interface to L<ElasticSearch> |
546
|
|
|
|
|
|
|
and integration with L<ElasticSearch::SearchBuilder>. |
547
|
|
|
|
|
|
|
|
548
|
|
|
|
|
|
|
=back |
549
|
|
|
|
|
|
|
|
550
|
|
|
|
|
|
|
=head1 BUGS |
551
|
|
|
|
|
|
|
|
552
|
|
|
|
|
|
|
This is a stable API but this implementation is new. Watch this space |
553
|
|
|
|
|
|
|
for new releases. |
554
|
|
|
|
|
|
|
|
555
|
|
|
|
|
|
|
If you have any suggestions for improvements, or find any bugs, please report |
556
|
|
|
|
|
|
|
them to L<http://github.com/elasticsearch/elasticsearch-perl/issues>. |
557
|
|
|
|
|
|
|
I will be notified, and then you'll automatically be notified of progress on |
558
|
|
|
|
|
|
|
your bug as I make changes. |
559
|
|
|
|
|
|
|
|
560
|
|
|
|
|
|
|
=head1 SUPPORT |
561
|
|
|
|
|
|
|
|
562
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
563
|
|
|
|
|
|
|
|
564
|
|
|
|
|
|
|
perldoc Elasticsearch |
565
|
|
|
|
|
|
|
|
566
|
|
|
|
|
|
|
You can also look for information at: |
567
|
|
|
|
|
|
|
|
568
|
|
|
|
|
|
|
=over 4 |
569
|
|
|
|
|
|
|
|
570
|
|
|
|
|
|
|
=item * GitHub |
571
|
|
|
|
|
|
|
|
572
|
|
|
|
|
|
|
L<http://github.com/elasticsearch/elasticsearch-perl> |
573
|
|
|
|
|
|
|
|
574
|
|
|
|
|
|
|
=item * CPAN Ratings |
575
|
|
|
|
|
|
|
|
576
|
|
|
|
|
|
|
L<http://cpanratings.perl.org/d/Elasticsearch> |
577
|
|
|
|
|
|
|
|
578
|
|
|
|
|
|
|
=item * Search MetaCPAN |
579
|
|
|
|
|
|
|
|
580
|
|
|
|
|
|
|
L<https://metacpan.org/module/Elasticsearch> |
581
|
|
|
|
|
|
|
|
582
|
|
|
|
|
|
|
=item * IRC |
583
|
|
|
|
|
|
|
|
584
|
|
|
|
|
|
|
The L<#elasticsearch|irc://irc.freenode.net/elasticsearch> channel on |
585
|
|
|
|
|
|
|
C<irc.freenode.net>. |
586
|
|
|
|
|
|
|
|
587
|
|
|
|
|
|
|
=item * Mailing list |
588
|
|
|
|
|
|
|
|
589
|
|
|
|
|
|
|
The main L<Elasticsearch mailing list|http://www.elasticsearch.org/community/forum/>. |
590
|
|
|
|
|
|
|
|
591
|
|
|
|
|
|
|
=back |
592
|
|
|
|
|
|
|
|
593
|
|
|
|
|
|
|
=head1 TEST SUITE |
594
|
|
|
|
|
|
|
|
595
|
|
|
|
|
|
|
The full test suite requires a live Elasticsearch node to run, and should |
596
|
|
|
|
|
|
|
be run as : |
597
|
|
|
|
|
|
|
|
598
|
|
|
|
|
|
|
perl Makefile.PL |
599
|
|
|
|
|
|
|
ES=localhost:9200 make test |
600
|
|
|
|
|
|
|
|
601
|
|
|
|
|
|
|
B<TESTS RUN IN THIS WAY ARE DESTRUCTIVE! DO NOT RUN AGAINST A CLUSTER WITH |
602
|
|
|
|
|
|
|
DATA YOU WANT TO KEEP!> |
603
|
|
|
|
|
|
|
|
604
|
|
|
|
|
|
|
You can change the Cxn class which is used by setting the C<ES_CXN> |
605
|
|
|
|
|
|
|
environment variable: |
606
|
|
|
|
|
|
|
|
607
|
|
|
|
|
|
|
ES_CXN=HTTPTiny ES=localhost:9200 make test |
608
|
|
|
|
|
|
|
|
609
|
|
|
|
|
|
|
=head1 AUTHOR |
610
|
|
|
|
|
|
|
|
611
|
|
|
|
|
|
|
Clinton Gormley <drtech@cpan.org> |
612
|
|
|
|
|
|
|
|
613
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
614
|
|
|
|
|
|
|
|
615
|
|
|
|
|
|
|
This software is Copyright (c) 2014 by Elasticsearch BV. |
616
|
|
|
|
|
|
|
|
617
|
|
|
|
|
|
|
This is free software, licensed under: |
618
|
|
|
|
|
|
|
|
619
|
|
|
|
|
|
|
The Apache License, Version 2.0, January 2004 |
620
|
|
|
|
|
|
|
|
621
|
|
|
|
|
|
|
=cut |
622
|
|
|
|
|
|
|
|
623
|
|
|
|
|
|
|
__END__ |
624
|
|
|
|
|
|
|
|
625
|
|
|
|
|
|
|
# ABSTRACT: DEPRECATED: The official client for Elasticsearch |
626
|
|
|
|
|
|
|
|