line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Elasticsearch::Client::Direct; |
2
|
|
|
|
|
|
|
$Elasticsearch::Client::Direct::VERSION = '1.05'; |
3
|
42
|
|
|
42
|
|
40984
|
use Moo; |
|
42
|
|
|
|
|
106
|
|
|
42
|
|
|
|
|
346
|
|
4
|
|
|
|
|
|
|
with 'Elasticsearch::Role::API'; |
5
|
|
|
|
|
|
|
with 'Elasticsearch::Role::Client::Direct'; |
6
|
|
|
|
|
|
|
|
7
|
42
|
|
|
42
|
|
18860
|
use Elasticsearch::Util qw(parse_params load_plugin is_compat); |
|
42
|
|
|
|
|
106
|
|
|
42
|
|
|
|
|
446
|
|
8
|
42
|
|
|
42
|
|
22996
|
use namespace::clean; |
|
42
|
|
|
|
|
99
|
|
|
42
|
|
|
|
|
391
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
has 'cluster' => ( is => 'lazy', init_arg => undef ); |
11
|
|
|
|
|
|
|
has 'nodes' => ( is => 'lazy', init_arg => undef ); |
12
|
|
|
|
|
|
|
has 'indices' => ( is => 'lazy', init_arg => undef ); |
13
|
|
|
|
|
|
|
has 'snapshot' => ( is => 'lazy', init_arg => undef ); |
14
|
|
|
|
|
|
|
has 'cat' => ( is => 'lazy', init_arg => undef ); |
15
|
|
|
|
|
|
|
has 'bulk_helper_class' => ( is => 'ro', default => 'Bulk' ); |
16
|
|
|
|
|
|
|
has 'scroll_helper_class' => ( is => 'ro', default => 'Scroll' ); |
17
|
|
|
|
|
|
|
has '_bulk_class' => ( is => 'lazy' ); |
18
|
|
|
|
|
|
|
has '_scroll_class' => ( is => 'lazy' ); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
__PACKAGE__->_install_api(''); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
#=================================== |
23
|
|
|
|
|
|
|
sub create { |
24
|
|
|
|
|
|
|
#=================================== |
25
|
0
|
|
|
0
|
1
|
|
my ( $self, $params ) = parse_params(@_); |
26
|
0
|
|
|
|
|
|
$params->{op_type} = 'create'; |
27
|
0
|
|
|
|
|
|
$self->_index( 'create', $params ); |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
#=================================== |
31
|
|
|
|
|
|
|
sub index { |
32
|
|
|
|
|
|
|
#=================================== |
33
|
0
|
|
|
0
|
1
|
|
my ( $self, $params ) = parse_params(@_); |
34
|
0
|
|
|
|
|
|
$self->_index( 'index', $params ); |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
#=================================== |
38
|
|
|
|
|
|
|
sub _index { |
39
|
|
|
|
|
|
|
#=================================== |
40
|
0
|
|
|
0
|
|
|
my ( $self, $name, $params ) = @_; |
41
|
0
|
|
|
|
|
|
my $defn = $self->api->{index}; |
42
|
0
|
0
|
0
|
|
|
|
unless ( defined $params->{id} and length $params->{id} ) { |
43
|
0
|
|
|
|
|
|
$defn = { %$defn, method => 'POST' }; |
44
|
|
|
|
|
|
|
} |
45
|
0
|
|
|
|
|
|
$self->perform_request( { %$defn, name => $name }, $params ); |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
#=================================== |
49
|
|
|
|
|
|
|
sub _build__bulk_class { |
50
|
|
|
|
|
|
|
#=================================== |
51
|
0
|
|
|
0
|
|
|
my $self = shift; |
52
|
0
|
|
|
|
|
|
$self->_build_helper( 'bulk', $self->bulk_helper_class ); |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
#=================================== |
56
|
|
|
|
|
|
|
sub _build__scroll_class { |
57
|
|
|
|
|
|
|
#=================================== |
58
|
0
|
|
|
0
|
|
|
my $self = shift; |
59
|
0
|
|
|
|
|
|
$self->_build_helper( 'scroll', $self->scroll_helper_class ); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
#=================================== |
63
|
|
|
|
|
|
|
sub _build_helper { |
64
|
|
|
|
|
|
|
#=================================== |
65
|
0
|
|
|
0
|
|
|
my ( $self, $name, $sub_class ) = @_; |
66
|
0
|
|
|
|
|
|
my $class = load_plugin( 'Elasticsearch', $sub_class ); |
67
|
0
|
|
|
|
|
|
is_compat( $name . '_helper_class', $self->transport, $class ); |
68
|
0
|
|
|
|
|
|
return $class; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
#=================================== |
72
|
|
|
|
|
|
|
sub bulk_helper { |
73
|
|
|
|
|
|
|
#=================================== |
74
|
0
|
|
|
0
|
1
|
|
my ( $self, $params ) = parse_params(@_); |
75
|
0
|
|
0
|
|
|
|
$params->{es} ||= $self; |
76
|
0
|
|
|
|
|
|
$self->_bulk_class->new($params); |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
#=================================== |
80
|
|
|
|
|
|
|
sub scroll_helper { |
81
|
|
|
|
|
|
|
#=================================== |
82
|
0
|
|
|
0
|
1
|
|
my ( $self, $params ) = parse_params(@_); |
83
|
0
|
|
0
|
|
|
|
$params->{es} ||= $self; |
84
|
0
|
|
|
|
|
|
$self->_scroll_class->new($params); |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
#=================================== |
88
|
0
|
|
|
0
|
|
|
sub _build_cluster { shift->_build_namespace('Cluster') } |
89
|
0
|
|
|
0
|
|
|
sub _build_nodes { shift->_build_namespace('Nodes') } |
90
|
0
|
|
|
0
|
|
|
sub _build_indices { shift->_build_namespace('Indices') } |
91
|
0
|
|
|
0
|
|
|
sub _build_snapshot { shift->_build_namespace('Snapshot') } |
92
|
0
|
|
|
0
|
|
|
sub _build_cat { shift->_build_namespace('Cat') } |
93
|
|
|
|
|
|
|
#=================================== |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
#=================================== |
96
|
|
|
|
|
|
|
sub _build_namespace { |
97
|
|
|
|
|
|
|
#=================================== |
98
|
0
|
|
|
0
|
|
|
my ( $self, $ns ) = @_; |
99
|
0
|
|
|
|
|
|
my $class = load_plugin( __PACKAGE__, [$ns] ); |
100
|
0
|
|
|
|
|
|
return $class->new( |
101
|
|
|
|
|
|
|
{ transport => $self->transport, |
102
|
|
|
|
|
|
|
logger => $self->logger |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
); |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
1; |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=pod |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=encoding UTF-8 |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=head1 NAME |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
Elasticsearch::Client::Direct - Thin client with full support for Elasticsearch APIs |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=head1 VERSION |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
version 1.05 |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=head1 SYNOPSIS |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
Create a client: |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
use Elasticsearch; |
126
|
|
|
|
|
|
|
my $e = Elasticsearch->new( |
127
|
|
|
|
|
|
|
client => 'Direct' # default |
128
|
|
|
|
|
|
|
); |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
Index a doc: |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
$e->index( |
133
|
|
|
|
|
|
|
index => 'my_index', |
134
|
|
|
|
|
|
|
type => 'blog_post', |
135
|
|
|
|
|
|
|
id => 123, |
136
|
|
|
|
|
|
|
body => { |
137
|
|
|
|
|
|
|
title => "Elasticsearch clients", |
138
|
|
|
|
|
|
|
content => "Interesting content...", |
139
|
|
|
|
|
|
|
date => "2013-09-23" |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
); |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
Get a doc: |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
$e->get( |
146
|
|
|
|
|
|
|
index => 'my_index', |
147
|
|
|
|
|
|
|
type => 'my_type', |
148
|
|
|
|
|
|
|
id => 123 |
149
|
|
|
|
|
|
|
); |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
Search for docs: |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
$results = $e->search( |
154
|
|
|
|
|
|
|
index => 'my_index', |
155
|
|
|
|
|
|
|
body => { |
156
|
|
|
|
|
|
|
query => { |
157
|
|
|
|
|
|
|
match => { |
158
|
|
|
|
|
|
|
title => "elasticsearch" |
159
|
|
|
|
|
|
|
} |
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
); |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
Index-level requests: |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
$e->indices->create( index => 'my_index' ); |
167
|
|
|
|
|
|
|
$e->indices->delete( index => 'my_index' ) |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
Cluster-level requests: |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
$health = $e->cluster->health; |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
Node-level requests: |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
$info = $e->nodes->info; |
176
|
|
|
|
|
|
|
$stats = $e->nodes->stats; |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
Snapshot and restore: |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
$e->snapshot->create_repository( |
181
|
|
|
|
|
|
|
repository => 'my_backups', |
182
|
|
|
|
|
|
|
type => 'fs', |
183
|
|
|
|
|
|
|
settings => { |
184
|
|
|
|
|
|
|
location => '/mnt/backups' |
185
|
|
|
|
|
|
|
} |
186
|
|
|
|
|
|
|
); |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
$e->snapshot->create( |
189
|
|
|
|
|
|
|
repository => 'my_backups', |
190
|
|
|
|
|
|
|
snapshot => 'backup_2014' |
191
|
|
|
|
|
|
|
); |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
`cat` debugging: |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
say $e->cat->allocation; |
196
|
|
|
|
|
|
|
say $e->cat->health; |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
=head1 DESCRIPTION |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
The L<Elasticsearch::Client::Direct> class provides the default |
201
|
|
|
|
|
|
|
client that is returned by: |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
$e = Elasticsearch->new; |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
It is intended to be as close as possible to the native REST API that |
206
|
|
|
|
|
|
|
Elasticsearch uses, so that it is easy to translate the |
207
|
|
|
|
|
|
|
L<Elasticsearch reference documentation|http://www.elasticsearch/guide> |
208
|
|
|
|
|
|
|
for an API to the equivalent in this client. |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
This class provides the methods for L<document CRUD|/DOCUMENT CRUD METHODS>, |
211
|
|
|
|
|
|
|
L<bulk document CRUD|/BULK DOCUMENT CRUD METHODS> and L<search|/SEARCH METHODS>. |
212
|
|
|
|
|
|
|
It also provides access to clients for managing L<indices|/indices()> |
213
|
|
|
|
|
|
|
and the L<cluster|/cluster()>. |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
=head1 BACKWARDS COMPATIBILITY AND ELASTICSEARCH 0.90.x |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
This version of the client supports the Elasticsearch 1.0 branch by |
218
|
|
|
|
|
|
|
default, which is not backwards compatible with the 0.90 branch. |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
If you need to talk to a version of Elasticsearch before 1.0.0, |
221
|
|
|
|
|
|
|
please use L<Elasticsearch::Client::0_90::Direct> as follows: |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
$es = Elasticsearch->new( |
224
|
|
|
|
|
|
|
client => '0_90::Direct' |
225
|
|
|
|
|
|
|
); |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
=head1 CONVENTIONS |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
=head2 Parameter passing |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
Parameters can be passed to any request method as a list or as a hash |
232
|
|
|
|
|
|
|
reference. The following two statements are equivalent: |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
$e->search( size => 10 ); |
235
|
|
|
|
|
|
|
$e->search({size => 10}); |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
=head2 Path parameters |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
Any values that should be included in the URL path, eg C</{index}/{type}> |
240
|
|
|
|
|
|
|
should be passed as top level parameters: |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
$e->search( index => 'my_index', type => 'my_type' ); |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
Alternatively, you can specify a C<path> parameter directly: |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
$e->search( path => '/my_index/my_type' ); |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
=head2 Query-string parameters |
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
Any values that should be included in the query string should be passed |
251
|
|
|
|
|
|
|
as top level parameters: |
252
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
$e->search( size => 10 ); |
254
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
If you pass in a C<\%params> hash, then it will be included in the |
256
|
|
|
|
|
|
|
query string parameters without any error checking. The following: |
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
$e->search( size => 10, params => { from => 5, size => 5 }) |
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
would result in this query string: |
261
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
?from=5&size=10 |
263
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
=head2 Body parameter |
265
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
The request body should be passed in the C<body> key: |
267
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
$e->search( |
269
|
|
|
|
|
|
|
body => { |
270
|
|
|
|
|
|
|
query => {...} |
271
|
|
|
|
|
|
|
} |
272
|
|
|
|
|
|
|
); |
273
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
The body can also be a UTF8-decoded string, which will be converted into |
275
|
|
|
|
|
|
|
UTF-8 bytes and passed as is: |
276
|
|
|
|
|
|
|
|
277
|
|
|
|
|
|
|
$e->analyze( body => "The quick brown fox"); |
278
|
|
|
|
|
|
|
|
279
|
|
|
|
|
|
|
=head2 Ignore parameter |
280
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
Normally, any HTTP status code outside the 200-299 range will result in |
282
|
|
|
|
|
|
|
an error being thrown. To suppress these errors, you can specify which |
283
|
|
|
|
|
|
|
status codes to ignore in the C<ignore> parameter. |
284
|
|
|
|
|
|
|
|
285
|
|
|
|
|
|
|
$e->indices->delete( |
286
|
|
|
|
|
|
|
index => 'my_index', |
287
|
|
|
|
|
|
|
ignore => 404 |
288
|
|
|
|
|
|
|
); |
289
|
|
|
|
|
|
|
|
290
|
|
|
|
|
|
|
This is most useful for |
291
|
|
|
|
|
|
|
L<Missing|Elasticsearch::Error/Elasticsearch::Error::Missing> errors, which |
292
|
|
|
|
|
|
|
are triggered by a C<404> status code when some requested resource does |
293
|
|
|
|
|
|
|
not exist. |
294
|
|
|
|
|
|
|
|
295
|
|
|
|
|
|
|
Multiple error codes can be specified with an array: |
296
|
|
|
|
|
|
|
|
297
|
|
|
|
|
|
|
$e->indices->delete( |
298
|
|
|
|
|
|
|
index => 'my_index', |
299
|
|
|
|
|
|
|
ignore => [404,409] |
300
|
|
|
|
|
|
|
); |
301
|
|
|
|
|
|
|
|
302
|
|
|
|
|
|
|
=head1 CONFIGURATION |
303
|
|
|
|
|
|
|
|
304
|
|
|
|
|
|
|
=head2 C<bulk_helper_class> |
305
|
|
|
|
|
|
|
|
306
|
|
|
|
|
|
|
The class to use for the L</bulk_helper()> method. Defaults to |
307
|
|
|
|
|
|
|
L<Elasticsearch::Bulk>. |
308
|
|
|
|
|
|
|
|
309
|
|
|
|
|
|
|
=head2 C<scroll_helper_class> |
310
|
|
|
|
|
|
|
|
311
|
|
|
|
|
|
|
The class to use for the L</scroll_helper()> method. Defaults to |
312
|
|
|
|
|
|
|
L<Elasticsearch::Scroll>. |
313
|
|
|
|
|
|
|
|
314
|
|
|
|
|
|
|
=head1 GENERAL METHODS |
315
|
|
|
|
|
|
|
|
316
|
|
|
|
|
|
|
=head2 C<info()> |
317
|
|
|
|
|
|
|
|
318
|
|
|
|
|
|
|
$info = $e->info |
319
|
|
|
|
|
|
|
|
320
|
|
|
|
|
|
|
Returns information about the version of Elasticsearch that the responding node |
321
|
|
|
|
|
|
|
is running. |
322
|
|
|
|
|
|
|
|
323
|
|
|
|
|
|
|
=head2 C<ping()> |
324
|
|
|
|
|
|
|
|
325
|
|
|
|
|
|
|
$e->ping |
326
|
|
|
|
|
|
|
|
327
|
|
|
|
|
|
|
Pings a node in the cluster and returns C<1> if it receives a C<200> |
328
|
|
|
|
|
|
|
response, otherwise it throws an error. |
329
|
|
|
|
|
|
|
|
330
|
|
|
|
|
|
|
=head2 C<indices()> |
331
|
|
|
|
|
|
|
|
332
|
|
|
|
|
|
|
$indices_client = $e->indices; |
333
|
|
|
|
|
|
|
|
334
|
|
|
|
|
|
|
Returns an L<Elasticsearch::Client::Direct::Indices> object which can be used |
335
|
|
|
|
|
|
|
for managing indices, eg creating, deleting indices, managing mapping, |
336
|
|
|
|
|
|
|
index settings etc. |
337
|
|
|
|
|
|
|
|
338
|
|
|
|
|
|
|
=head2 C<cluster()> |
339
|
|
|
|
|
|
|
|
340
|
|
|
|
|
|
|
$cluster_client = $e->cluster; |
341
|
|
|
|
|
|
|
|
342
|
|
|
|
|
|
|
Returns an L<Elasticsearch::Client::Direct::Cluster> object which can be used |
343
|
|
|
|
|
|
|
for managing the cluster, eg cluster-wide settings and cluster health. |
344
|
|
|
|
|
|
|
|
345
|
|
|
|
|
|
|
=head2 C<nodes()> |
346
|
|
|
|
|
|
|
|
347
|
|
|
|
|
|
|
$node_client = $e->nodes; |
348
|
|
|
|
|
|
|
|
349
|
|
|
|
|
|
|
Returns an L<Elasticsearch::Client::Direct::Nodes> object which can be used |
350
|
|
|
|
|
|
|
to retrieve node info and stats. |
351
|
|
|
|
|
|
|
|
352
|
|
|
|
|
|
|
=head2 C<snapshot()> |
353
|
|
|
|
|
|
|
|
354
|
|
|
|
|
|
|
$snapshot_client = $e->snapshot; |
355
|
|
|
|
|
|
|
|
356
|
|
|
|
|
|
|
Returns an L<Elasticsearch::Client::Direct::Snapshot> object which |
357
|
|
|
|
|
|
|
is used for managing backup repositories and creating and restoring |
358
|
|
|
|
|
|
|
snapshots. |
359
|
|
|
|
|
|
|
|
360
|
|
|
|
|
|
|
=head2 C<cat()> |
361
|
|
|
|
|
|
|
|
362
|
|
|
|
|
|
|
$cat_client = $e->cat; |
363
|
|
|
|
|
|
|
|
364
|
|
|
|
|
|
|
Returns an L<Elasticsearch::Client::Direct::Cat> object which can be used |
365
|
|
|
|
|
|
|
to retrieve simple to read text info for debugging and monitoring an |
366
|
|
|
|
|
|
|
Elasticsearch cluster. |
367
|
|
|
|
|
|
|
|
368
|
|
|
|
|
|
|
=head1 DOCUMENT CRUD METHODS |
369
|
|
|
|
|
|
|
|
370
|
|
|
|
|
|
|
These methods allow you to perform create, index, update and delete requests |
371
|
|
|
|
|
|
|
for single documents: |
372
|
|
|
|
|
|
|
|
373
|
|
|
|
|
|
|
=head2 C<index()> |
374
|
|
|
|
|
|
|
|
375
|
|
|
|
|
|
|
$response = $e->index( |
376
|
|
|
|
|
|
|
index => 'index_name', # required |
377
|
|
|
|
|
|
|
type => 'type_name', # required |
378
|
|
|
|
|
|
|
id => 'doc_id', # optional, otherwise auto-generated |
379
|
|
|
|
|
|
|
|
380
|
|
|
|
|
|
|
body => { document } # required |
381
|
|
|
|
|
|
|
); |
382
|
|
|
|
|
|
|
|
383
|
|
|
|
|
|
|
The C<index()> method is used to index a new document or to reindex |
384
|
|
|
|
|
|
|
an existing document. |
385
|
|
|
|
|
|
|
|
386
|
|
|
|
|
|
|
Query string parameters: |
387
|
|
|
|
|
|
|
C<consistency>, |
388
|
|
|
|
|
|
|
C<op_type>, |
389
|
|
|
|
|
|
|
C<parent>, |
390
|
|
|
|
|
|
|
C<refresh>, |
391
|
|
|
|
|
|
|
C<replication>, |
392
|
|
|
|
|
|
|
C<routing>, |
393
|
|
|
|
|
|
|
C<timeout>, |
394
|
|
|
|
|
|
|
C<timestamp>, |
395
|
|
|
|
|
|
|
C<ttl>, |
396
|
|
|
|
|
|
|
C<version>, |
397
|
|
|
|
|
|
|
C<version_type> |
398
|
|
|
|
|
|
|
|
399
|
|
|
|
|
|
|
See the L<index docs|http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/docs-index_.html> |
400
|
|
|
|
|
|
|
for more information. |
401
|
|
|
|
|
|
|
|
402
|
|
|
|
|
|
|
=head2 C<create()> |
403
|
|
|
|
|
|
|
|
404
|
|
|
|
|
|
|
$response = $e->create( |
405
|
|
|
|
|
|
|
index => 'index_name', # required |
406
|
|
|
|
|
|
|
type => 'type_name', # required |
407
|
|
|
|
|
|
|
id => 'doc_id', # optional, otherwise auto-generated |
408
|
|
|
|
|
|
|
|
409
|
|
|
|
|
|
|
body => { document } # required |
410
|
|
|
|
|
|
|
); |
411
|
|
|
|
|
|
|
|
412
|
|
|
|
|
|
|
The C<create()> method works exactly like the L</index()> method, except |
413
|
|
|
|
|
|
|
that it will throw a C<Conflict> error if a document with the same |
414
|
|
|
|
|
|
|
C<index>, C<type> and C<id> already exists. |
415
|
|
|
|
|
|
|
|
416
|
|
|
|
|
|
|
Query string parameters: |
417
|
|
|
|
|
|
|
C<consistency>, |
418
|
|
|
|
|
|
|
C<op_type>, |
419
|
|
|
|
|
|
|
C<parent>, |
420
|
|
|
|
|
|
|
C<refresh>, |
421
|
|
|
|
|
|
|
C<replication>, |
422
|
|
|
|
|
|
|
C<routing>, |
423
|
|
|
|
|
|
|
C<timeout>, |
424
|
|
|
|
|
|
|
C<timestamp>, |
425
|
|
|
|
|
|
|
C<ttl>, |
426
|
|
|
|
|
|
|
C<version>, |
427
|
|
|
|
|
|
|
C<version_type> |
428
|
|
|
|
|
|
|
|
429
|
|
|
|
|
|
|
See the L<create docs|http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/docs-create.html> |
430
|
|
|
|
|
|
|
for more information. |
431
|
|
|
|
|
|
|
|
432
|
|
|
|
|
|
|
=head2 C<get()> |
433
|
|
|
|
|
|
|
|
434
|
|
|
|
|
|
|
$response = $e->get( |
435
|
|
|
|
|
|
|
index => 'index_name', # required |
436
|
|
|
|
|
|
|
type => 'type_name', # required |
437
|
|
|
|
|
|
|
id => 'doc_id', # required |
438
|
|
|
|
|
|
|
); |
439
|
|
|
|
|
|
|
|
440
|
|
|
|
|
|
|
The C<get()> method will retrieve the document with the specified |
441
|
|
|
|
|
|
|
C<index>, C<type> and C<id>, or will throw a C<Missing> error. |
442
|
|
|
|
|
|
|
|
443
|
|
|
|
|
|
|
Query string parameters: |
444
|
|
|
|
|
|
|
C<_source>, |
445
|
|
|
|
|
|
|
C<_source_exclude>, |
446
|
|
|
|
|
|
|
C<_source_include>, |
447
|
|
|
|
|
|
|
C<fields>, |
448
|
|
|
|
|
|
|
C<parent>, |
449
|
|
|
|
|
|
|
C<preference>, |
450
|
|
|
|
|
|
|
C<realtime>, |
451
|
|
|
|
|
|
|
C<refresh>, |
452
|
|
|
|
|
|
|
C<routing>, |
453
|
|
|
|
|
|
|
C<version>, |
454
|
|
|
|
|
|
|
C<version_type> |
455
|
|
|
|
|
|
|
|
456
|
|
|
|
|
|
|
See the L<get docs|http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/docs-get.html> |
457
|
|
|
|
|
|
|
for more information. |
458
|
|
|
|
|
|
|
|
459
|
|
|
|
|
|
|
=head2 C<get_source()> |
460
|
|
|
|
|
|
|
|
461
|
|
|
|
|
|
|
$response = $e->get_source( |
462
|
|
|
|
|
|
|
index => 'index_name', # required |
463
|
|
|
|
|
|
|
type => 'type_name', # required |
464
|
|
|
|
|
|
|
id => 'doc_id', # required |
465
|
|
|
|
|
|
|
); |
466
|
|
|
|
|
|
|
|
467
|
|
|
|
|
|
|
The C<get_source()> method works just like the L</get()> method except that |
468
|
|
|
|
|
|
|
it returns just the C<_source> field (the value of the C<body> parameter |
469
|
|
|
|
|
|
|
in the L</index()> method) instead of returning the C<_source> field |
470
|
|
|
|
|
|
|
plus the document metadata, ie the C<_index>, C<_type> etc. |
471
|
|
|
|
|
|
|
|
472
|
|
|
|
|
|
|
Query string parameters: |
473
|
|
|
|
|
|
|
C<_source>, |
474
|
|
|
|
|
|
|
C<_source_exclude>, |
475
|
|
|
|
|
|
|
C<_source_include>, |
476
|
|
|
|
|
|
|
C<parent>, |
477
|
|
|
|
|
|
|
C<preference>, |
478
|
|
|
|
|
|
|
C<realtime>, |
479
|
|
|
|
|
|
|
C<refresh>, |
480
|
|
|
|
|
|
|
C<routing>, |
481
|
|
|
|
|
|
|
C<version>, |
482
|
|
|
|
|
|
|
C<version_type> |
483
|
|
|
|
|
|
|
|
484
|
|
|
|
|
|
|
See the L<get_source docs|http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/docs-get.html> |
485
|
|
|
|
|
|
|
for more information. |
486
|
|
|
|
|
|
|
|
487
|
|
|
|
|
|
|
=head2 C<exists()> |
488
|
|
|
|
|
|
|
|
489
|
|
|
|
|
|
|
$response = $e->exists( |
490
|
|
|
|
|
|
|
index => 'index_name', # required |
491
|
|
|
|
|
|
|
type => 'type_name', # required |
492
|
|
|
|
|
|
|
id => 'doc_id', # required |
493
|
|
|
|
|
|
|
); |
494
|
|
|
|
|
|
|
|
495
|
|
|
|
|
|
|
The C<exists()> method returns C<1> if a document with the specified |
496
|
|
|
|
|
|
|
C<index>, C<type> and C<id> exists, or an empty string if it doesn't. |
497
|
|
|
|
|
|
|
|
498
|
|
|
|
|
|
|
Query string parameters: |
499
|
|
|
|
|
|
|
C<parent>, |
500
|
|
|
|
|
|
|
C<preference>, |
501
|
|
|
|
|
|
|
C<realtime>, |
502
|
|
|
|
|
|
|
C<refresh>, |
503
|
|
|
|
|
|
|
C<routing> |
504
|
|
|
|
|
|
|
|
505
|
|
|
|
|
|
|
See the L<exists docs|http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/docs-get.html> |
506
|
|
|
|
|
|
|
for more information. |
507
|
|
|
|
|
|
|
|
508
|
|
|
|
|
|
|
=head2 C<delete()> |
509
|
|
|
|
|
|
|
|
510
|
|
|
|
|
|
|
$response = $e->delete( |
511
|
|
|
|
|
|
|
index => 'index_name', # required |
512
|
|
|
|
|
|
|
type => 'type_name', # required |
513
|
|
|
|
|
|
|
id => 'doc_id', # required |
514
|
|
|
|
|
|
|
); |
515
|
|
|
|
|
|
|
|
516
|
|
|
|
|
|
|
The C<delete()> method will delete the document with the specified |
517
|
|
|
|
|
|
|
C<index>, C<type> and C<id>, or will throw a C<Missing> error. |
518
|
|
|
|
|
|
|
|
519
|
|
|
|
|
|
|
Query string parameters: |
520
|
|
|
|
|
|
|
C<consistency>, |
521
|
|
|
|
|
|
|
C<parent>, |
522
|
|
|
|
|
|
|
C<refresh>, |
523
|
|
|
|
|
|
|
C<replication>, |
524
|
|
|
|
|
|
|
C<routing>, |
525
|
|
|
|
|
|
|
C<timeout>, |
526
|
|
|
|
|
|
|
C<version>, |
527
|
|
|
|
|
|
|
C<version_type> |
528
|
|
|
|
|
|
|
|
529
|
|
|
|
|
|
|
See the L<delete docs|http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/docs-delete.html> |
530
|
|
|
|
|
|
|
for more information. |
531
|
|
|
|
|
|
|
|
532
|
|
|
|
|
|
|
=head2 C<update()> |
533
|
|
|
|
|
|
|
|
534
|
|
|
|
|
|
|
$response = $e->update( |
535
|
|
|
|
|
|
|
index => 'index_name', # required |
536
|
|
|
|
|
|
|
type => 'type_name', # required |
537
|
|
|
|
|
|
|
id => 'doc_id', # required |
538
|
|
|
|
|
|
|
|
539
|
|
|
|
|
|
|
body => { update } # required |
540
|
|
|
|
|
|
|
); |
541
|
|
|
|
|
|
|
|
542
|
|
|
|
|
|
|
The C<update()> method updates a document with the corresponding |
543
|
|
|
|
|
|
|
C<index>, C<type> and C<id> if it exists. Updates can be performed either by: |
544
|
|
|
|
|
|
|
|
545
|
|
|
|
|
|
|
=over |
546
|
|
|
|
|
|
|
|
547
|
|
|
|
|
|
|
=item * providing a partial document to be merged in to the existing document: |
548
|
|
|
|
|
|
|
|
549
|
|
|
|
|
|
|
$response = $e->update( |
550
|
|
|
|
|
|
|
..., |
551
|
|
|
|
|
|
|
body => { |
552
|
|
|
|
|
|
|
doc => { new_field => 'new_value'}, |
553
|
|
|
|
|
|
|
} |
554
|
|
|
|
|
|
|
); |
555
|
|
|
|
|
|
|
|
556
|
|
|
|
|
|
|
=item * or with a script: |
557
|
|
|
|
|
|
|
|
558
|
|
|
|
|
|
|
$response = $e->update( |
559
|
|
|
|
|
|
|
..., |
560
|
|
|
|
|
|
|
body => { |
561
|
|
|
|
|
|
|
script => "ctx._source.counter += incr", |
562
|
|
|
|
|
|
|
params => { incr => 5 } |
563
|
|
|
|
|
|
|
} |
564
|
|
|
|
|
|
|
); |
565
|
|
|
|
|
|
|
|
566
|
|
|
|
|
|
|
=back |
567
|
|
|
|
|
|
|
|
568
|
|
|
|
|
|
|
Query string parameters: |
569
|
|
|
|
|
|
|
C<consistency>, |
570
|
|
|
|
|
|
|
C<fields>, |
571
|
|
|
|
|
|
|
C<lang>, |
572
|
|
|
|
|
|
|
C<parent>, |
573
|
|
|
|
|
|
|
C<realtime>, |
574
|
|
|
|
|
|
|
C<refresh>, |
575
|
|
|
|
|
|
|
C<replication>, |
576
|
|
|
|
|
|
|
C<retry_on_conflict>, |
577
|
|
|
|
|
|
|
C<routing>, |
578
|
|
|
|
|
|
|
C<script>, |
579
|
|
|
|
|
|
|
C<timeout>, |
580
|
|
|
|
|
|
|
C<timestamp>, |
581
|
|
|
|
|
|
|
C<ttl>, |
582
|
|
|
|
|
|
|
C<version>, |
583
|
|
|
|
|
|
|
C<version_type> |
584
|
|
|
|
|
|
|
|
585
|
|
|
|
|
|
|
See the L<update docs|http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/docs-update.html> |
586
|
|
|
|
|
|
|
for more information. |
587
|
|
|
|
|
|
|
|
588
|
|
|
|
|
|
|
=head2 C<termvector()> |
589
|
|
|
|
|
|
|
|
590
|
|
|
|
|
|
|
$results = $e->termvector( |
591
|
|
|
|
|
|
|
index => $index, # required |
592
|
|
|
|
|
|
|
type => $type, # required |
593
|
|
|
|
|
|
|
id => $id, # required |
594
|
|
|
|
|
|
|
|
595
|
|
|
|
|
|
|
body => {...} # optional |
596
|
|
|
|
|
|
|
) |
597
|
|
|
|
|
|
|
|
598
|
|
|
|
|
|
|
The C<termvector()> method retrieves term and field statistics, positions, |
599
|
|
|
|
|
|
|
offsets and payloads for the specified document, assuming that termvectors |
600
|
|
|
|
|
|
|
have been enabled. |
601
|
|
|
|
|
|
|
|
602
|
|
|
|
|
|
|
Query string parameters: |
603
|
|
|
|
|
|
|
C<field_statistics>, |
604
|
|
|
|
|
|
|
C<fields>, |
605
|
|
|
|
|
|
|
C<offsets>, |
606
|
|
|
|
|
|
|
C<parent>, |
607
|
|
|
|
|
|
|
C<payloads>, |
608
|
|
|
|
|
|
|
C<positions>, |
609
|
|
|
|
|
|
|
C<preference>, |
610
|
|
|
|
|
|
|
C<routing>, |
611
|
|
|
|
|
|
|
C<term_statistics> |
612
|
|
|
|
|
|
|
|
613
|
|
|
|
|
|
|
See the L<termvector docs|http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/docs-termvectors.html> |
614
|
|
|
|
|
|
|
for more information. |
615
|
|
|
|
|
|
|
|
616
|
|
|
|
|
|
|
=head1 BULK DOCUMENT CRUD METHODS |
617
|
|
|
|
|
|
|
|
618
|
|
|
|
|
|
|
The bulk document CRUD methods are used for running multiple CRUD actions |
619
|
|
|
|
|
|
|
within a single request. By reducing the number of network requests |
620
|
|
|
|
|
|
|
that need to be made, bulk requests greatly improve performance. |
621
|
|
|
|
|
|
|
|
622
|
|
|
|
|
|
|
=head2 C<bulk()> |
623
|
|
|
|
|
|
|
|
624
|
|
|
|
|
|
|
$response = $e->bulk( |
625
|
|
|
|
|
|
|
index => 'index_name', # required if type specified |
626
|
|
|
|
|
|
|
type => 'type_name', # optional |
627
|
|
|
|
|
|
|
|
628
|
|
|
|
|
|
|
body => [ actions ] # required |
629
|
|
|
|
|
|
|
); |
630
|
|
|
|
|
|
|
|
631
|
|
|
|
|
|
|
See L<Elasticsearch::Bulk> and L</bulk_helper()> for a helper module that makes |
632
|
|
|
|
|
|
|
bulk indexing simpler to use. |
633
|
|
|
|
|
|
|
|
634
|
|
|
|
|
|
|
The C<bulk()> method can perform multiple L</index()>, L</create()>, |
635
|
|
|
|
|
|
|
L</delete()> or L</update()> actions with a single request. The C<body> |
636
|
|
|
|
|
|
|
parameter expects an array containing the list of actions to perform. |
637
|
|
|
|
|
|
|
|
638
|
|
|
|
|
|
|
An I<action> consists of an initial metadata hash ref containing the action |
639
|
|
|
|
|
|
|
type, plus the associated metadata, eg : |
640
|
|
|
|
|
|
|
|
641
|
|
|
|
|
|
|
{ delete => { _index => 'index', _type => 'type', _id => 123 }} |
642
|
|
|
|
|
|
|
|
643
|
|
|
|
|
|
|
The C<index> and C<create> actions then expect a hashref containing |
644
|
|
|
|
|
|
|
the document itself: |
645
|
|
|
|
|
|
|
|
646
|
|
|
|
|
|
|
{ create => { _index => 'index', _type => 'type', _id => 123 }}, |
647
|
|
|
|
|
|
|
{ title => "A newly created document" } |
648
|
|
|
|
|
|
|
|
649
|
|
|
|
|
|
|
And the C<update> action expects a hashref containing the update commands, |
650
|
|
|
|
|
|
|
eg: |
651
|
|
|
|
|
|
|
|
652
|
|
|
|
|
|
|
{ update => { _index => 'index', _type => 'type', _id => 123 }}, |
653
|
|
|
|
|
|
|
{ script => "ctx._source.counter+=1" } |
654
|
|
|
|
|
|
|
|
655
|
|
|
|
|
|
|
Each action can include the same parameters that you would pass to |
656
|
|
|
|
|
|
|
the equivalent L</index()>, L</create()>, L</delete()> or L</update()> |
657
|
|
|
|
|
|
|
request, except that C<_index>, C<_type> and C<_id> must be specified with |
658
|
|
|
|
|
|
|
the preceding underscore. All other parameters can be specified with or |
659
|
|
|
|
|
|
|
without the underscore. |
660
|
|
|
|
|
|
|
|
661
|
|
|
|
|
|
|
For instance: |
662
|
|
|
|
|
|
|
|
663
|
|
|
|
|
|
|
$response = $e->bulk( |
664
|
|
|
|
|
|
|
index => 'index_name', # default index name |
665
|
|
|
|
|
|
|
type => 'type_name', # default type name |
666
|
|
|
|
|
|
|
body => [ |
667
|
|
|
|
|
|
|
|
668
|
|
|
|
|
|
|
# create action |
669
|
|
|
|
|
|
|
{ create => { |
670
|
|
|
|
|
|
|
_index => 'not_the_default_index', |
671
|
|
|
|
|
|
|
_type => 'not_the_default_type', |
672
|
|
|
|
|
|
|
_id => 123 |
673
|
|
|
|
|
|
|
}}, |
674
|
|
|
|
|
|
|
{ title => 'Foo' }, |
675
|
|
|
|
|
|
|
|
676
|
|
|
|
|
|
|
# index action |
677
|
|
|
|
|
|
|
{ index => { _id => 124 }}, |
678
|
|
|
|
|
|
|
{ title => 'Foo' }, |
679
|
|
|
|
|
|
|
|
680
|
|
|
|
|
|
|
# delete action |
681
|
|
|
|
|
|
|
{ delete => { _id => 125 }}, |
682
|
|
|
|
|
|
|
|
683
|
|
|
|
|
|
|
# update action |
684
|
|
|
|
|
|
|
{ update => { _id => 126 }}, |
685
|
|
|
|
|
|
|
{ script => "ctx._source.counter+1" } |
686
|
|
|
|
|
|
|
] |
687
|
|
|
|
|
|
|
); |
688
|
|
|
|
|
|
|
|
689
|
|
|
|
|
|
|
Each action is performed separately. One failed action will not |
690
|
|
|
|
|
|
|
cause the others to fail as well. |
691
|
|
|
|
|
|
|
|
692
|
|
|
|
|
|
|
Query string parameters: |
693
|
|
|
|
|
|
|
C<consistency>, |
694
|
|
|
|
|
|
|
C<refresh>, |
695
|
|
|
|
|
|
|
C<replication>, |
696
|
|
|
|
|
|
|
C<timeout> |
697
|
|
|
|
|
|
|
|
698
|
|
|
|
|
|
|
See the L<bulk docs|http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/docs-bulk.html> |
699
|
|
|
|
|
|
|
for more information. |
700
|
|
|
|
|
|
|
|
701
|
|
|
|
|
|
|
=head2 C<bulk_helper()> |
702
|
|
|
|
|
|
|
|
703
|
|
|
|
|
|
|
$bulk_helper = $e->bulk_helper( @args ); |
704
|
|
|
|
|
|
|
|
705
|
|
|
|
|
|
|
Returns a new instance of the class specified in the L</bulk_helper_class>, |
706
|
|
|
|
|
|
|
which defaults to L<Elasticsearch::Bulk>. |
707
|
|
|
|
|
|
|
|
708
|
|
|
|
|
|
|
=head2 C<mget()> |
709
|
|
|
|
|
|
|
|
710
|
|
|
|
|
|
|
$results = $e->mget( |
711
|
|
|
|
|
|
|
index => 'default_index', # optional, required when type specified |
712
|
|
|
|
|
|
|
type => 'default_type', # optional |
713
|
|
|
|
|
|
|
|
714
|
|
|
|
|
|
|
body => { docs or ids } # required |
715
|
|
|
|
|
|
|
); |
716
|
|
|
|
|
|
|
|
717
|
|
|
|
|
|
|
The C<mget()> method will retrieve multiple documents with a single request. |
718
|
|
|
|
|
|
|
The C<body> consists of an array of documents to retrieve: |
719
|
|
|
|
|
|
|
|
720
|
|
|
|
|
|
|
$results = $e->mget( |
721
|
|
|
|
|
|
|
index => 'default_index', |
722
|
|
|
|
|
|
|
type => 'default_type', |
723
|
|
|
|
|
|
|
body => { |
724
|
|
|
|
|
|
|
docs => [ |
725
|
|
|
|
|
|
|
{ _id => 1}, |
726
|
|
|
|
|
|
|
{ _id => 2, _type => 'not_the_default_type' } |
727
|
|
|
|
|
|
|
] |
728
|
|
|
|
|
|
|
} |
729
|
|
|
|
|
|
|
); |
730
|
|
|
|
|
|
|
|
731
|
|
|
|
|
|
|
You can also pass any of the other parameters that the L</get()> request |
732
|
|
|
|
|
|
|
accepts. |
733
|
|
|
|
|
|
|
|
734
|
|
|
|
|
|
|
If you have specified an C<index> and C<type>, you can just include the |
735
|
|
|
|
|
|
|
C<ids> of the documents to retrieve: |
736
|
|
|
|
|
|
|
|
737
|
|
|
|
|
|
|
$results = $e->mget( |
738
|
|
|
|
|
|
|
index => 'default_index', |
739
|
|
|
|
|
|
|
type => 'default_type', |
740
|
|
|
|
|
|
|
body => { |
741
|
|
|
|
|
|
|
ids => [ 1, 2, 3] |
742
|
|
|
|
|
|
|
} |
743
|
|
|
|
|
|
|
); |
744
|
|
|
|
|
|
|
|
745
|
|
|
|
|
|
|
Query string parameters: |
746
|
|
|
|
|
|
|
C<_source>, |
747
|
|
|
|
|
|
|
C<_source_exclude>, |
748
|
|
|
|
|
|
|
C<_source_include>, |
749
|
|
|
|
|
|
|
C<fields>, |
750
|
|
|
|
|
|
|
C<preference>, |
751
|
|
|
|
|
|
|
C<realtime>, |
752
|
|
|
|
|
|
|
C<refresh> |
753
|
|
|
|
|
|
|
|
754
|
|
|
|
|
|
|
See the L<mget docs|http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/docs-multi-get.html> |
755
|
|
|
|
|
|
|
for more information. |
756
|
|
|
|
|
|
|
|
757
|
|
|
|
|
|
|
=head2 C<delete_by_query()> |
758
|
|
|
|
|
|
|
|
759
|
|
|
|
|
|
|
$result = $e->delete_by_query( |
760
|
|
|
|
|
|
|
index => 'index' | \@indices, # required |
761
|
|
|
|
|
|
|
type => 'type' | \@types, # optional |
762
|
|
|
|
|
|
|
|
763
|
|
|
|
|
|
|
body => { query } # required |
764
|
|
|
|
|
|
|
|
765
|
|
|
|
|
|
|
); |
766
|
|
|
|
|
|
|
|
767
|
|
|
|
|
|
|
The C<delete_by_query()> method deletes all documents which match the |
768
|
|
|
|
|
|
|
query. For instance, to delete all documents from 2012: |
769
|
|
|
|
|
|
|
|
770
|
|
|
|
|
|
|
$result = $e->delete_by_query( |
771
|
|
|
|
|
|
|
body => { |
772
|
|
|
|
|
|
|
query => { |
773
|
|
|
|
|
|
|
range => { |
774
|
|
|
|
|
|
|
date => { |
775
|
|
|
|
|
|
|
gte => '2012-01-01', |
776
|
|
|
|
|
|
|
lt => '2013-01-01' |
777
|
|
|
|
|
|
|
} |
778
|
|
|
|
|
|
|
} |
779
|
|
|
|
|
|
|
} |
780
|
|
|
|
|
|
|
} |
781
|
|
|
|
|
|
|
); |
782
|
|
|
|
|
|
|
|
783
|
|
|
|
|
|
|
Query string parameters: |
784
|
|
|
|
|
|
|
C<allow_no_indices>, |
785
|
|
|
|
|
|
|
C<analyzer>, |
786
|
|
|
|
|
|
|
C<consistency>, |
787
|
|
|
|
|
|
|
C<default_operator>, |
788
|
|
|
|
|
|
|
C<df>, |
789
|
|
|
|
|
|
|
C<expand_wildcards>, |
790
|
|
|
|
|
|
|
C<ignore_unavailable>, |
791
|
|
|
|
|
|
|
C<q>, |
792
|
|
|
|
|
|
|
C<replication>, |
793
|
|
|
|
|
|
|
C<routing>, |
794
|
|
|
|
|
|
|
C<source>, |
795
|
|
|
|
|
|
|
C<timeout> |
796
|
|
|
|
|
|
|
|
797
|
|
|
|
|
|
|
See the L<delete_by_query docs|http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/docs-delete-by-query.html> |
798
|
|
|
|
|
|
|
for more information. |
799
|
|
|
|
|
|
|
|
800
|
|
|
|
|
|
|
=head2 C<mtermvectors()> |
801
|
|
|
|
|
|
|
|
802
|
|
|
|
|
|
|
$results = $e->mtermvectors( |
803
|
|
|
|
|
|
|
index => $index, # required if type specified |
804
|
|
|
|
|
|
|
type => $type, # optional |
805
|
|
|
|
|
|
|
|
806
|
|
|
|
|
|
|
body => { } # optional |
807
|
|
|
|
|
|
|
) |
808
|
|
|
|
|
|
|
|
809
|
|
|
|
|
|
|
Runs multiple L</termvector()> requests in a single request, eg: |
810
|
|
|
|
|
|
|
|
811
|
|
|
|
|
|
|
$results = $e->mtermvectors( |
812
|
|
|
|
|
|
|
index => 'test', |
813
|
|
|
|
|
|
|
body => { |
814
|
|
|
|
|
|
|
docs => [ |
815
|
|
|
|
|
|
|
{ _type => 'test', _id => 1, fields => ['text'] }, |
816
|
|
|
|
|
|
|
{ _type => 'test', _id => 2, payloads => 1 }, |
817
|
|
|
|
|
|
|
] |
818
|
|
|
|
|
|
|
} |
819
|
|
|
|
|
|
|
); |
820
|
|
|
|
|
|
|
|
821
|
|
|
|
|
|
|
Query string parameters: |
822
|
|
|
|
|
|
|
C<field_statistics>, |
823
|
|
|
|
|
|
|
C<fields>, |
824
|
|
|
|
|
|
|
C<ids>, |
825
|
|
|
|
|
|
|
C<offsets>, |
826
|
|
|
|
|
|
|
C<parent>, |
827
|
|
|
|
|
|
|
C<payloads>, |
828
|
|
|
|
|
|
|
C<positions>, |
829
|
|
|
|
|
|
|
C<preference>, |
830
|
|
|
|
|
|
|
C<routing>, |
831
|
|
|
|
|
|
|
C<term_statistics> |
832
|
|
|
|
|
|
|
|
833
|
|
|
|
|
|
|
See the L<mtermvectors docs|http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/docs-multi-termvectors.html> |
834
|
|
|
|
|
|
|
for more information. |
835
|
|
|
|
|
|
|
|
836
|
|
|
|
|
|
|
=head1 SEARCH METHODS |
837
|
|
|
|
|
|
|
|
838
|
|
|
|
|
|
|
The search methods are used for querying documents in one, more or all indices |
839
|
|
|
|
|
|
|
and of one, more or all types: |
840
|
|
|
|
|
|
|
|
841
|
|
|
|
|
|
|
=head2 C<search()> |
842
|
|
|
|
|
|
|
|
843
|
|
|
|
|
|
|
$results = $e->search( |
844
|
|
|
|
|
|
|
index => 'index' | \@indices, # optional |
845
|
|
|
|
|
|
|
type => 'type' | \@types, # optional |
846
|
|
|
|
|
|
|
|
847
|
|
|
|
|
|
|
body => { search params } # optional |
848
|
|
|
|
|
|
|
); |
849
|
|
|
|
|
|
|
|
850
|
|
|
|
|
|
|
The C<search()> method searches for matching documents in one or more |
851
|
|
|
|
|
|
|
indices. It is just as easy to search a single index as it is to search |
852
|
|
|
|
|
|
|
all the indices in your cluster. It can also return |
853
|
|
|
|
|
|
|
L<aggregations|http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations.html> |
854
|
|
|
|
|
|
|
L<highlighted snippets|http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-highlighting.html> |
855
|
|
|
|
|
|
|
and L<did-you-mean|http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-suggesters-phrase.html> |
856
|
|
|
|
|
|
|
or L<search-as-you-type|http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-suggesters-completion.html> |
857
|
|
|
|
|
|
|
suggestions. |
858
|
|
|
|
|
|
|
|
859
|
|
|
|
|
|
|
The I<lite> L<version of search|http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-uri-request.html> |
860
|
|
|
|
|
|
|
allows you to specify a query string in the C<q> parameter, using the |
861
|
|
|
|
|
|
|
Lucene query string syntax: |
862
|
|
|
|
|
|
|
|
863
|
|
|
|
|
|
|
$results = $e->search( q => 'title:(elasticsearch clients)'); |
864
|
|
|
|
|
|
|
|
865
|
|
|
|
|
|
|
However, the preferred way to search is by using the |
866
|
|
|
|
|
|
|
L<Query DSL|http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl.html> |
867
|
|
|
|
|
|
|
to create a query, and passing that C<query> in the |
868
|
|
|
|
|
|
|
L<request body|http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-request-body.html>: |
869
|
|
|
|
|
|
|
|
870
|
|
|
|
|
|
|
$results = $e->search( |
871
|
|
|
|
|
|
|
body => { |
872
|
|
|
|
|
|
|
query => { |
873
|
|
|
|
|
|
|
match => { title => 'Elasticsearch clients'} |
874
|
|
|
|
|
|
|
} |
875
|
|
|
|
|
|
|
} |
876
|
|
|
|
|
|
|
); |
877
|
|
|
|
|
|
|
|
878
|
|
|
|
|
|
|
Query string parameters: |
879
|
|
|
|
|
|
|
C<_source>, |
880
|
|
|
|
|
|
|
C<_source_exclude>, |
881
|
|
|
|
|
|
|
C<_source_include>, |
882
|
|
|
|
|
|
|
C<allow_no_indices>, |
883
|
|
|
|
|
|
|
C<analyze_wildcard>, |
884
|
|
|
|
|
|
|
C<analyzer>, |
885
|
|
|
|
|
|
|
C<default_operator>, |
886
|
|
|
|
|
|
|
C<df>, |
887
|
|
|
|
|
|
|
C<expand_wildcards>, |
888
|
|
|
|
|
|
|
C<explain>, |
889
|
|
|
|
|
|
|
C<fields>, |
890
|
|
|
|
|
|
|
C<from>, |
891
|
|
|
|
|
|
|
C<ignore_unavailable>, |
892
|
|
|
|
|
|
|
C<indices_boost>, |
893
|
|
|
|
|
|
|
C<lenient>, |
894
|
|
|
|
|
|
|
C<lowercase_expanded_terms>, |
895
|
|
|
|
|
|
|
C<preference>, |
896
|
|
|
|
|
|
|
C<q>, |
897
|
|
|
|
|
|
|
C<routing>, |
898
|
|
|
|
|
|
|
C<scroll>, |
899
|
|
|
|
|
|
|
C<search_type>, |
900
|
|
|
|
|
|
|
C<size>, |
901
|
|
|
|
|
|
|
C<sort>, |
902
|
|
|
|
|
|
|
C<source>, |
903
|
|
|
|
|
|
|
C<stats>, |
904
|
|
|
|
|
|
|
C<suggest_field>, |
905
|
|
|
|
|
|
|
C<suggest_mode>, |
906
|
|
|
|
|
|
|
C<suggest_size>, |
907
|
|
|
|
|
|
|
C<suggest_text>, |
908
|
|
|
|
|
|
|
C<timeout>, |
909
|
|
|
|
|
|
|
C<version> |
910
|
|
|
|
|
|
|
|
911
|
|
|
|
|
|
|
See the L<search reference|http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-request-body.html> |
912
|
|
|
|
|
|
|
for more information. |
913
|
|
|
|
|
|
|
|
914
|
|
|
|
|
|
|
Also see L<Elasticsearch::Transport/send_get_body_as>. |
915
|
|
|
|
|
|
|
|
916
|
|
|
|
|
|
|
=head2 C<count()> |
917
|
|
|
|
|
|
|
|
918
|
|
|
|
|
|
|
$results = $e->count( |
919
|
|
|
|
|
|
|
index => 'index' | \@indices, # optional |
920
|
|
|
|
|
|
|
type => 'type' | \@types, # optional |
921
|
|
|
|
|
|
|
|
922
|
|
|
|
|
|
|
body => { query } # optional |
923
|
|
|
|
|
|
|
) |
924
|
|
|
|
|
|
|
|
925
|
|
|
|
|
|
|
The C<count()> method returns the total count of all documents matching the |
926
|
|
|
|
|
|
|
query: |
927
|
|
|
|
|
|
|
|
928
|
|
|
|
|
|
|
$results = $e->count( |
929
|
|
|
|
|
|
|
body => { |
930
|
|
|
|
|
|
|
query => { |
931
|
|
|
|
|
|
|
match => { title => 'Elasticsearch clients' } |
932
|
|
|
|
|
|
|
} |
933
|
|
|
|
|
|
|
} |
934
|
|
|
|
|
|
|
); |
935
|
|
|
|
|
|
|
|
936
|
|
|
|
|
|
|
Query string parameters: |
937
|
|
|
|
|
|
|
C<allow_no_indices>, |
938
|
|
|
|
|
|
|
C<expand_wildcards>, |
939
|
|
|
|
|
|
|
C<ignore_unavailable>, |
940
|
|
|
|
|
|
|
C<min_score>, |
941
|
|
|
|
|
|
|
C<preference>, |
942
|
|
|
|
|
|
|
C<routing>, |
943
|
|
|
|
|
|
|
C<source> |
944
|
|
|
|
|
|
|
|
945
|
|
|
|
|
|
|
See the L<count docs|http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-count.html> |
946
|
|
|
|
|
|
|
for more information. |
947
|
|
|
|
|
|
|
|
948
|
|
|
|
|
|
|
=head2 C<scroll()> |
949
|
|
|
|
|
|
|
|
950
|
|
|
|
|
|
|
$results = $e->scroll( |
951
|
|
|
|
|
|
|
scroll => '1m', |
952
|
|
|
|
|
|
|
scroll_id => $id |
953
|
|
|
|
|
|
|
); |
954
|
|
|
|
|
|
|
|
955
|
|
|
|
|
|
|
When a L</search()> has been performed with the |
956
|
|
|
|
|
|
|
C<scroll> parameter, the C<scroll()> |
957
|
|
|
|
|
|
|
method allows you to keep pulling more results until the results |
958
|
|
|
|
|
|
|
are exhausted. |
959
|
|
|
|
|
|
|
|
960
|
|
|
|
|
|
|
B<NOTE:> you will almost always want to set the |
961
|
|
|
|
|
|
|
C<search_type> to C<scan> in your |
962
|
|
|
|
|
|
|
original C<search()> request. |
963
|
|
|
|
|
|
|
|
964
|
|
|
|
|
|
|
See L</scroll_helper()> and L<Elasticsearch::Scroll> for a helper utility |
965
|
|
|
|
|
|
|
which makes managing scroll requests much easier. |
966
|
|
|
|
|
|
|
|
967
|
|
|
|
|
|
|
Query string parameters: |
968
|
|
|
|
|
|
|
C<scroll>, |
969
|
|
|
|
|
|
|
C<scroll_id> |
970
|
|
|
|
|
|
|
|
971
|
|
|
|
|
|
|
See the L<scroll docs|http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-request-scroll.html> |
972
|
|
|
|
|
|
|
and the L<search_type docs|http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search.html/search-request-search-type.html> |
973
|
|
|
|
|
|
|
for more information. |
974
|
|
|
|
|
|
|
|
975
|
|
|
|
|
|
|
=head2 C<clear_scroll()> |
976
|
|
|
|
|
|
|
|
977
|
|
|
|
|
|
|
$response = $e->clear_scroll( |
978
|
|
|
|
|
|
|
scroll_id => $id | \@ids # required |
979
|
|
|
|
|
|
|
); |
980
|
|
|
|
|
|
|
|
981
|
|
|
|
|
|
|
The C<clear_scroll()> method can clear unfinished scroll requests, freeing |
982
|
|
|
|
|
|
|
up resources on the server. |
983
|
|
|
|
|
|
|
|
984
|
|
|
|
|
|
|
=head2 C<scroll_helper()> |
985
|
|
|
|
|
|
|
|
986
|
|
|
|
|
|
|
$scroll_helper = $e->scroll_helper( @args ); |
987
|
|
|
|
|
|
|
|
988
|
|
|
|
|
|
|
Returns a new instance of the class specified in the L</scroll_helper_class>, |
989
|
|
|
|
|
|
|
which defaults to L<Elasticsearch::Scroll>. |
990
|
|
|
|
|
|
|
|
991
|
|
|
|
|
|
|
=head2 C<msearch()> |
992
|
|
|
|
|
|
|
|
993
|
|
|
|
|
|
|
$results = $e->msearch( |
994
|
|
|
|
|
|
|
index => 'default_index' | \@indices, # optional |
995
|
|
|
|
|
|
|
type => 'default_type' | \@types, # optional |
996
|
|
|
|
|
|
|
|
997
|
|
|
|
|
|
|
body => [ searches ] # required |
998
|
|
|
|
|
|
|
); |
999
|
|
|
|
|
|
|
|
1000
|
|
|
|
|
|
|
The C<msearch()> method allows you to perform multiple searches in a single |
1001
|
|
|
|
|
|
|
request. Similar to the L</bulk()> request, each search request in the |
1002
|
|
|
|
|
|
|
C<body> consists of two hashes: the metadata hash then the search request |
1003
|
|
|
|
|
|
|
hash (the same data that you'd specify in the C<body> of a L</search()> |
1004
|
|
|
|
|
|
|
request). For instance: |
1005
|
|
|
|
|
|
|
|
1006
|
|
|
|
|
|
|
$results = $e->msearch( |
1007
|
|
|
|
|
|
|
index => 'default_index', |
1008
|
|
|
|
|
|
|
type => ['default_type_1', 'default_type_2'], |
1009
|
|
|
|
|
|
|
body => [ |
1010
|
|
|
|
|
|
|
# uses defaults |
1011
|
|
|
|
|
|
|
{}, |
1012
|
|
|
|
|
|
|
{ query => { match_all => {} }}, |
1013
|
|
|
|
|
|
|
|
1014
|
|
|
|
|
|
|
# uses a custom index |
1015
|
|
|
|
|
|
|
{ index => 'not_the_default_index' }, |
1016
|
|
|
|
|
|
|
{ query => { match_all => {} }} |
1017
|
|
|
|
|
|
|
] |
1018
|
|
|
|
|
|
|
); |
1019
|
|
|
|
|
|
|
|
1020
|
|
|
|
|
|
|
Query string parameters: |
1021
|
|
|
|
|
|
|
C<search_type> |
1022
|
|
|
|
|
|
|
|
1023
|
|
|
|
|
|
|
See the L<msearch docs|http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-multi-search.html> |
1024
|
|
|
|
|
|
|
for more information. |
1025
|
|
|
|
|
|
|
|
1026
|
|
|
|
|
|
|
=head2 C<explain()> |
1027
|
|
|
|
|
|
|
|
1028
|
|
|
|
|
|
|
$response = $e->explain( |
1029
|
|
|
|
|
|
|
index => 'my_index', # required |
1030
|
|
|
|
|
|
|
type => 'my_type', # required |
1031
|
|
|
|
|
|
|
id => 123, # required |
1032
|
|
|
|
|
|
|
|
1033
|
|
|
|
|
|
|
body => { search } # required |
1034
|
|
|
|
|
|
|
); |
1035
|
|
|
|
|
|
|
|
1036
|
|
|
|
|
|
|
The C<explain()> method explains why the specified document did or |
1037
|
|
|
|
|
|
|
did not match a query, and how the relevance score was calculated. |
1038
|
|
|
|
|
|
|
For instance: |
1039
|
|
|
|
|
|
|
|
1040
|
|
|
|
|
|
|
$response = $e->explain( |
1041
|
|
|
|
|
|
|
index => 'my_index', |
1042
|
|
|
|
|
|
|
type => 'my_type', |
1043
|
|
|
|
|
|
|
id => 123, |
1044
|
|
|
|
|
|
|
body => { |
1045
|
|
|
|
|
|
|
query => { |
1046
|
|
|
|
|
|
|
match => { title => 'Elasticsearch clients' } |
1047
|
|
|
|
|
|
|
} |
1048
|
|
|
|
|
|
|
} |
1049
|
|
|
|
|
|
|
); |
1050
|
|
|
|
|
|
|
|
1051
|
|
|
|
|
|
|
Query string parameters: |
1052
|
|
|
|
|
|
|
C<_source>, |
1053
|
|
|
|
|
|
|
C<_source_exclude>, |
1054
|
|
|
|
|
|
|
C<_source_include>, |
1055
|
|
|
|
|
|
|
C<analyze_wildcard>, |
1056
|
|
|
|
|
|
|
C<analyzer>, |
1057
|
|
|
|
|
|
|
C<default_operator>, |
1058
|
|
|
|
|
|
|
C<df>, |
1059
|
|
|
|
|
|
|
C<fields>, |
1060
|
|
|
|
|
|
|
C<lenient>, |
1061
|
|
|
|
|
|
|
C<lowercase_expanded_terms>, |
1062
|
|
|
|
|
|
|
C<parent>, |
1063
|
|
|
|
|
|
|
C<preference>, |
1064
|
|
|
|
|
|
|
C<q>, |
1065
|
|
|
|
|
|
|
C<routing>, |
1066
|
|
|
|
|
|
|
C<source> |
1067
|
|
|
|
|
|
|
|
1068
|
|
|
|
|
|
|
See the L<explain docs|http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-explain.html> |
1069
|
|
|
|
|
|
|
for more information. |
1070
|
|
|
|
|
|
|
|
1071
|
|
|
|
|
|
|
=head2 C<percolate()> |
1072
|
|
|
|
|
|
|
|
1073
|
|
|
|
|
|
|
$results = $e->percolate( |
1074
|
|
|
|
|
|
|
index => 'my_index', # required |
1075
|
|
|
|
|
|
|
type => 'my_type', # required |
1076
|
|
|
|
|
|
|
|
1077
|
|
|
|
|
|
|
body => { percolation } # required |
1078
|
|
|
|
|
|
|
); |
1079
|
|
|
|
|
|
|
|
1080
|
|
|
|
|
|
|
Percolation is search inverted: instead of finding docs which match a |
1081
|
|
|
|
|
|
|
particular query, it finds queries which match a particular document, eg |
1082
|
|
|
|
|
|
|
for I<alert-me-when> functionality. |
1083
|
|
|
|
|
|
|
|
1084
|
|
|
|
|
|
|
The C<percolate()> method runs a percolation request to find the |
1085
|
|
|
|
|
|
|
queries matching a particular document. In the C<body> you should pass the |
1086
|
|
|
|
|
|
|
C<_source> field of the document under the C<doc> key: |
1087
|
|
|
|
|
|
|
|
1088
|
|
|
|
|
|
|
$results = $e->percolate( |
1089
|
|
|
|
|
|
|
index => 'my_index', |
1090
|
|
|
|
|
|
|
type => 'my_type', |
1091
|
|
|
|
|
|
|
body => { |
1092
|
|
|
|
|
|
|
doc => { |
1093
|
|
|
|
|
|
|
title => 'Elasticsearch rocks' |
1094
|
|
|
|
|
|
|
} |
1095
|
|
|
|
|
|
|
} |
1096
|
|
|
|
|
|
|
); |
1097
|
|
|
|
|
|
|
|
1098
|
|
|
|
|
|
|
Query string parameters: |
1099
|
|
|
|
|
|
|
C<allow_no_indices>, |
1100
|
|
|
|
|
|
|
C<expand_wildcards>, |
1101
|
|
|
|
|
|
|
C<ignore_unavailable>, |
1102
|
|
|
|
|
|
|
C<percolate_index>, |
1103
|
|
|
|
|
|
|
C<percolate_type>, |
1104
|
|
|
|
|
|
|
C<preference>, |
1105
|
|
|
|
|
|
|
C<routing>, |
1106
|
|
|
|
|
|
|
C<version>, |
1107
|
|
|
|
|
|
|
C<version_type> |
1108
|
|
|
|
|
|
|
|
1109
|
|
|
|
|
|
|
See the L<percolate docs|http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-percolate.html> |
1110
|
|
|
|
|
|
|
for more information. |
1111
|
|
|
|
|
|
|
|
1112
|
|
|
|
|
|
|
=head2 C<count_percolate()> |
1113
|
|
|
|
|
|
|
|
1114
|
|
|
|
|
|
|
$results = $e->count_percolate( |
1115
|
|
|
|
|
|
|
index => 'my_index', # required |
1116
|
|
|
|
|
|
|
type => 'my_type', # required |
1117
|
|
|
|
|
|
|
|
1118
|
|
|
|
|
|
|
body => { percolation } # required |
1119
|
|
|
|
|
|
|
); |
1120
|
|
|
|
|
|
|
|
1121
|
|
|
|
|
|
|
The L</count_percolate()> request works just like the L</percolate()> |
1122
|
|
|
|
|
|
|
request except that it returns a count of all matching queries, instead |
1123
|
|
|
|
|
|
|
of the queries themselves. |
1124
|
|
|
|
|
|
|
|
1125
|
|
|
|
|
|
|
$results = $e->count_percolate( |
1126
|
|
|
|
|
|
|
index => 'my_index', |
1127
|
|
|
|
|
|
|
type => 'my_type', |
1128
|
|
|
|
|
|
|
body => { |
1129
|
|
|
|
|
|
|
doc => { |
1130
|
|
|
|
|
|
|
title => 'Elasticsearch rocks' |
1131
|
|
|
|
|
|
|
} |
1132
|
|
|
|
|
|
|
} |
1133
|
|
|
|
|
|
|
); |
1134
|
|
|
|
|
|
|
|
1135
|
|
|
|
|
|
|
Query string parameters: |
1136
|
|
|
|
|
|
|
C<allow_no_indices>, |
1137
|
|
|
|
|
|
|
C<expand_wildcards>, |
1138
|
|
|
|
|
|
|
C<ignore_unavailable>, |
1139
|
|
|
|
|
|
|
C<percolate_index>, |
1140
|
|
|
|
|
|
|
C<percolate_type>, |
1141
|
|
|
|
|
|
|
C<preference>, |
1142
|
|
|
|
|
|
|
C<routing>, |
1143
|
|
|
|
|
|
|
C<version>, |
1144
|
|
|
|
|
|
|
C<version_type> |
1145
|
|
|
|
|
|
|
|
1146
|
|
|
|
|
|
|
See the L<percolate docs|http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-percolate.html> |
1147
|
|
|
|
|
|
|
for more information. |
1148
|
|
|
|
|
|
|
|
1149
|
|
|
|
|
|
|
=head2 C<mpercolate()> |
1150
|
|
|
|
|
|
|
|
1151
|
|
|
|
|
|
|
$results = $e->mpercolate( |
1152
|
|
|
|
|
|
|
index => 'my_index', # required if type |
1153
|
|
|
|
|
|
|
type => 'my_type', # optional |
1154
|
|
|
|
|
|
|
|
1155
|
|
|
|
|
|
|
body => [ percolation requests ] # required |
1156
|
|
|
|
|
|
|
); |
1157
|
|
|
|
|
|
|
|
1158
|
|
|
|
|
|
|
Multi-percolation allows multiple L</percolate()> requests to be run |
1159
|
|
|
|
|
|
|
in a single request. |
1160
|
|
|
|
|
|
|
|
1161
|
|
|
|
|
|
|
$results = $e->mpercolate( |
1162
|
|
|
|
|
|
|
index => 'my_index', |
1163
|
|
|
|
|
|
|
type => 'my_type', |
1164
|
|
|
|
|
|
|
body => [ |
1165
|
|
|
|
|
|
|
# first request |
1166
|
|
|
|
|
|
|
{ percolate => { |
1167
|
|
|
|
|
|
|
index => 'twitter', |
1168
|
|
|
|
|
|
|
type => 'tweet' |
1169
|
|
|
|
|
|
|
}}, |
1170
|
|
|
|
|
|
|
{ doc => {message => 'some_text' }}, |
1171
|
|
|
|
|
|
|
|
1172
|
|
|
|
|
|
|
# second request |
1173
|
|
|
|
|
|
|
{ percolate => { |
1174
|
|
|
|
|
|
|
index => 'twitter', |
1175
|
|
|
|
|
|
|
type => 'tweet', |
1176
|
|
|
|
|
|
|
id => 1 |
1177
|
|
|
|
|
|
|
}}, |
1178
|
|
|
|
|
|
|
{}, |
1179
|
|
|
|
|
|
|
] |
1180
|
|
|
|
|
|
|
); |
1181
|
|
|
|
|
|
|
|
1182
|
|
|
|
|
|
|
Query string parameters: |
1183
|
|
|
|
|
|
|
C<allow_no_indices>, |
1184
|
|
|
|
|
|
|
C<expand_wildcards>, |
1185
|
|
|
|
|
|
|
C<ignore_unavailable> |
1186
|
|
|
|
|
|
|
|
1187
|
|
|
|
|
|
|
See the L<mpercolate docs|http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-percolate.html> |
1188
|
|
|
|
|
|
|
for more information. |
1189
|
|
|
|
|
|
|
|
1190
|
|
|
|
|
|
|
=head2 C<suggest()> |
1191
|
|
|
|
|
|
|
|
1192
|
|
|
|
|
|
|
$results = $e->suggest( |
1193
|
|
|
|
|
|
|
index => 'index' | \@indices, # optional |
1194
|
|
|
|
|
|
|
|
1195
|
|
|
|
|
|
|
body => { suggest request } # required |
1196
|
|
|
|
|
|
|
); |
1197
|
|
|
|
|
|
|
|
1198
|
|
|
|
|
|
|
The C<suggest()> method is used to run |
1199
|
|
|
|
|
|
|
L<did-you-mean|http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-suggesteres-phrase.html> |
1200
|
|
|
|
|
|
|
or L<search-as-you-type|http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-suggesters-completion.html> |
1201
|
|
|
|
|
|
|
suggestion requests, which can also be run as part of a L</search()> request. |
1202
|
|
|
|
|
|
|
|
1203
|
|
|
|
|
|
|
$results = $e->suggest( |
1204
|
|
|
|
|
|
|
index => 'my_index', |
1205
|
|
|
|
|
|
|
body => { |
1206
|
|
|
|
|
|
|
my_suggestions => { |
1207
|
|
|
|
|
|
|
phrase => { |
1208
|
|
|
|
|
|
|
text => 'johnny walker', |
1209
|
|
|
|
|
|
|
field => 'title' |
1210
|
|
|
|
|
|
|
} |
1211
|
|
|
|
|
|
|
} |
1212
|
|
|
|
|
|
|
} |
1213
|
|
|
|
|
|
|
); |
1214
|
|
|
|
|
|
|
|
1215
|
|
|
|
|
|
|
Query string parameters: |
1216
|
|
|
|
|
|
|
C<allow_no_indices>, |
1217
|
|
|
|
|
|
|
C<expand_wildcards>, |
1218
|
|
|
|
|
|
|
C<ignore_unavailable>, |
1219
|
|
|
|
|
|
|
C<preference>, |
1220
|
|
|
|
|
|
|
C<routing>, |
1221
|
|
|
|
|
|
|
C<source> |
1222
|
|
|
|
|
|
|
|
1223
|
|
|
|
|
|
|
=head2 C<mlt()> |
1224
|
|
|
|
|
|
|
|
1225
|
|
|
|
|
|
|
$results = $e->mlt( |
1226
|
|
|
|
|
|
|
index => 'my_index', # required |
1227
|
|
|
|
|
|
|
type => 'my_type', # required |
1228
|
|
|
|
|
|
|
id => 123, # required |
1229
|
|
|
|
|
|
|
|
1230
|
|
|
|
|
|
|
body => { search } # optional |
1231
|
|
|
|
|
|
|
); |
1232
|
|
|
|
|
|
|
|
1233
|
|
|
|
|
|
|
The C<mlt()> method runs a |
1234
|
|
|
|
|
|
|
L<more-like-this query|http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-mlt-query.html> |
1235
|
|
|
|
|
|
|
to find other documents which are similar to the specified document. |
1236
|
|
|
|
|
|
|
|
1237
|
|
|
|
|
|
|
Query string parameters: |
1238
|
|
|
|
|
|
|
C<boost_terms>, |
1239
|
|
|
|
|
|
|
C<max_doc_freq>, |
1240
|
|
|
|
|
|
|
C<max_query_terms>, |
1241
|
|
|
|
|
|
|
C<max_word_length>, |
1242
|
|
|
|
|
|
|
C<min_doc_freq>, |
1243
|
|
|
|
|
|
|
C<min_term_freq>, |
1244
|
|
|
|
|
|
|
C<min_word_length>, |
1245
|
|
|
|
|
|
|
C<mlt_fields>, |
1246
|
|
|
|
|
|
|
C<percent_terms_to_match>, |
1247
|
|
|
|
|
|
|
C<routing>, |
1248
|
|
|
|
|
|
|
C<search_from>, |
1249
|
|
|
|
|
|
|
C<search_indices>, |
1250
|
|
|
|
|
|
|
C<search_query_hint>, |
1251
|
|
|
|
|
|
|
C<search_scroll>, |
1252
|
|
|
|
|
|
|
C<search_size>, |
1253
|
|
|
|
|
|
|
C<search_source>, |
1254
|
|
|
|
|
|
|
C<search_type>, |
1255
|
|
|
|
|
|
|
C<search_types>, |
1256
|
|
|
|
|
|
|
C<stop_words> |
1257
|
|
|
|
|
|
|
|
1258
|
|
|
|
|
|
|
See the L<mlt docs|http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-more-like-this.html> |
1259
|
|
|
|
|
|
|
for more information. |
1260
|
|
|
|
|
|
|
|
1261
|
|
|
|
|
|
|
=head1 AUTHOR |
1262
|
|
|
|
|
|
|
|
1263
|
|
|
|
|
|
|
Clinton Gormley <drtech@cpan.org> |
1264
|
|
|
|
|
|
|
|
1265
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
1266
|
|
|
|
|
|
|
|
1267
|
|
|
|
|
|
|
This software is Copyright (c) 2014 by Elasticsearch BV. |
1268
|
|
|
|
|
|
|
|
1269
|
|
|
|
|
|
|
This is free software, licensed under: |
1270
|
|
|
|
|
|
|
|
1271
|
|
|
|
|
|
|
The Apache License, Version 2.0, January 2004 |
1272
|
|
|
|
|
|
|
|
1273
|
|
|
|
|
|
|
=cut |
1274
|
|
|
|
|
|
|
|
1275
|
|
|
|
|
|
|
__END__ |
1276
|
|
|
|
|
|
|
|
1277
|
|
|
|
|
|
|
# ABSTRACT: Thin client with full support for Elasticsearch APIs |
1278
|
|
|
|
|
|
|
|