Filename | /opt/flows/lib/lib/perl5/Search/Elasticsearch/Client/2_0/Direct.pm |
Statements | Executed 11 statements in 1.01ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 17µs | 334µs | BEGIN@5 | Search::Elasticsearch::Client::2_0::Direct::
1 | 1 | 1 | 7µs | 42µs | __ANON__[:5] | Search::Elasticsearch::Client::2_0::Direct::
1 | 1 | 1 | 800ns | 800ns | _namespace | Search::Elasticsearch::Client::2_0::Direct::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package Search::Elasticsearch::Client::2_0::Direct; | ||||
2 | 1 | 800ns | $Search::Elasticsearch::Client::2_0::Direct::VERSION = '2.02'; | ||
3 | 1 | 4µs | # spent 800ns within Search::Elasticsearch::Client::2_0::Direct::_namespace which was called:
# once (800ns+0s) by Search::Elasticsearch::Role::Client::Direct::Main::_build_namespace at line 80 of /opt/flows/lib/lib/perl5/Search/Elasticsearch/Role/Client/Direct/Main.pm | ||
4 | |||||
5 | 4 | 986µs | 3 | 686µs | # spent 42µs (7+36) within Search::Elasticsearch::Client::2_0::Direct::__ANON__[/opt/flows/lib/lib/perl5/Search/Elasticsearch/Client/2_0/Direct.pm:5] which was called:
# once (7µs+36µs) by import::into at line 34 of Import/Into.pm
# spent 334µs (17+317) within Search::Elasticsearch::Client::2_0::Direct::BEGIN@5 which was called:
# once (17µs+317µs) by Module::Runtime::require_module at line 5 # spent 334µs making 1 call to Search::Elasticsearch::Client::2_0::Direct::BEGIN@5
# spent 317µs making 1 call to Moo::import
# spent 36µs making 1 call to strictures::import |
6 | 1 | 2µs | 1 | 10.2ms | with 'Search::Elasticsearch::Role::API::2_0'; # spent 10.2ms making 1 call to Moo::with |
7 | 1 | 900ns | 1 | 5.83ms | with 'Search::Elasticsearch::Role::Client::Direct'; # spent 5.83ms making 1 call to Moo::with |
8 | 1 | 1µs | 1 | 8.54ms | with 'Search::Elasticsearch::Role::Client::Direct::Main'; # spent 8.54ms making 1 call to Moo::with |
9 | |||||
10 | 1 | 6µs | 1 | 1.64ms | __PACKAGE__->_install_api(''); # spent 1.64ms making 1 call to Search::Elasticsearch::Role::Client::Direct::_install_api |
11 | |||||
12 | 1 | 6µs | 1; | ||
13 | |||||
14 | =pod | ||||
15 | |||||
16 | =encoding UTF-8 | ||||
17 | |||||
18 | =head1 NAME | ||||
19 | |||||
20 | Search::Elasticsearch::Client::2_0::Direct - Thin client with full support for Elasticsearch 2.x APIs | ||||
21 | |||||
22 | =head1 VERSION | ||||
23 | |||||
24 | version 2.02 | ||||
25 | |||||
26 | =head1 SYNOPSIS | ||||
27 | |||||
28 | Create a client: | ||||
29 | |||||
30 | use Search::Elasticsearch; | ||||
31 | my $e = Search::Elasticsearch->new( | ||||
32 | client => '2_0::Direct' | ||||
33 | ); | ||||
34 | |||||
35 | Index a doc: | ||||
36 | |||||
37 | $e->index( | ||||
38 | index => 'my_index', | ||||
39 | type => 'blog_post', | ||||
40 | id => 123, | ||||
41 | body => { | ||||
42 | title => "Elasticsearch clients", | ||||
43 | content => "Interesting content...", | ||||
44 | date => "2013-09-23" | ||||
45 | } | ||||
46 | ); | ||||
47 | |||||
48 | Get a doc: | ||||
49 | |||||
50 | $e->get( | ||||
51 | index => 'my_index', | ||||
52 | type => 'my_type', | ||||
53 | id => 123 | ||||
54 | ); | ||||
55 | |||||
56 | Search for docs: | ||||
57 | |||||
58 | $results = $e->search( | ||||
59 | index => 'my_index', | ||||
60 | body => { | ||||
61 | query => { | ||||
62 | match => { | ||||
63 | title => "elasticsearch" | ||||
64 | } | ||||
65 | } | ||||
66 | } | ||||
67 | ); | ||||
68 | |||||
69 | Index-level requests: | ||||
70 | |||||
71 | $e->indices->create( index => 'my_index' ); | ||||
72 | $e->indices->delete( index => 'my_index' ) | ||||
73 | |||||
74 | Cluster-level requests: | ||||
75 | |||||
76 | $health = $e->cluster->health; | ||||
77 | |||||
78 | Node-level requests: | ||||
79 | |||||
80 | $info = $e->nodes->info; | ||||
81 | $stats = $e->nodes->stats; | ||||
82 | |||||
83 | Snapshot and restore: | ||||
84 | |||||
85 | $e->snapshot->create_repository( | ||||
86 | repository => 'my_backups', | ||||
87 | type => 'fs', | ||||
88 | settings => { | ||||
89 | location => '/mnt/backups' | ||||
90 | } | ||||
91 | ); | ||||
92 | |||||
93 | $e->snapshot->create( | ||||
94 | repository => 'my_backups', | ||||
95 | snapshot => 'backup_2014' | ||||
96 | ); | ||||
97 | |||||
98 | Task management: | ||||
99 | |||||
100 | $e->tasks->list; | ||||
101 | |||||
102 | `cat` debugging: | ||||
103 | |||||
104 | say $e->cat->allocation; | ||||
105 | say $e->cat->health; | ||||
106 | |||||
107 | =head1 DESCRIPTION | ||||
108 | |||||
109 | The L<Search::Elasticsearch::Client::2_0::Direct> class provides a client | ||||
110 | compatible with the as-yet-unreleased version 2.x of Elasticsearch. | ||||
111 | |||||
112 | $e = Search::Elasticsearch->new( | ||||
113 | client => "2_0::Direct" | ||||
114 | ); | ||||
115 | |||||
116 | It is intended to be as close as possible to the native REST API that | ||||
117 | Elasticsearch uses, so that it is easy to translate the | ||||
118 | L<Elasticsearch reference documentation|http://www.elasticsearch/guide> | ||||
119 | for an API to the equivalent in this client. | ||||
120 | |||||
121 | This class provides the methods for L<document CRUD|/DOCUMENT CRUD METHODS>, | ||||
122 | L<bulk document CRUD|/BULK DOCUMENT CRUD METHODS> and L<search|/SEARCH METHODS>. | ||||
123 | It also provides access to clients for managing L<indices|/indices()> | ||||
124 | and the L<cluster|/cluster()>. | ||||
125 | |||||
126 | =head1 BACKWARDS COMPATIBILITY AND ELASTICSEARCH 1.x and 0.90.x | ||||
127 | |||||
128 | This version of the client supports the Elasticsearch 2.0 branch, | ||||
129 | which is not backwards compatible with the 1.x and 0.90 branch. | ||||
130 | |||||
131 | If you need to talk to a version of Elasticsearch before 2.0.0, | ||||
132 | please use L<Search::Elasticsearch::Client::1_0::Direct> | ||||
133 | or L<Search::Elasticsearch::Client::0_90::Direct> as follows: | ||||
134 | |||||
135 | $es = Search::Elasticsearch->new( | ||||
136 | client => '1_0::Direct' # or '0_90::Direct' | ||||
137 | ); | ||||
138 | |||||
139 | =head1 CONVENTIONS | ||||
140 | |||||
141 | =head2 Parameter passing | ||||
142 | |||||
143 | Parameters can be passed to any request method as a list or as a hash | ||||
144 | reference. The following two statements are equivalent: | ||||
145 | |||||
146 | $e->search( size => 10 ); | ||||
147 | $e->search({size => 10}); | ||||
148 | |||||
149 | =head2 Path parameters | ||||
150 | |||||
151 | Any values that should be included in the URL path, eg C</{index}/{type}> | ||||
152 | should be passed as top level parameters: | ||||
153 | |||||
154 | $e->search( index => 'my_index', type => 'my_type' ); | ||||
155 | |||||
156 | Alternatively, you can specify a C<path> parameter directly: | ||||
157 | |||||
158 | $e->search( path => '/my_index/my_type' ); | ||||
159 | |||||
160 | =head2 Query-string parameters | ||||
161 | |||||
162 | Any values that should be included in the query string should be passed | ||||
163 | as top level parameters: | ||||
164 | |||||
165 | $e->search( size => 10 ); | ||||
166 | |||||
167 | If you pass in a C<\%params> hash, then it will be included in the | ||||
168 | query string parameters without any error checking. The following: | ||||
169 | |||||
170 | $e->search( size => 10, params => { from => 5, size => 5 }) | ||||
171 | |||||
172 | would result in this query string: | ||||
173 | |||||
174 | ?from=5&size=10 | ||||
175 | |||||
176 | =head2 Body parameter | ||||
177 | |||||
178 | The request body should be passed in the C<body> key: | ||||
179 | |||||
180 | $e->search( | ||||
181 | body => { | ||||
182 | query => {...} | ||||
183 | } | ||||
184 | ); | ||||
185 | |||||
186 | The body can also be a UTF8-decoded string, which will be converted into | ||||
187 | UTF-8 bytes and passed as is: | ||||
188 | |||||
189 | $e->indices->analyze( body => "The quick brown fox"); | ||||
190 | |||||
191 | =head2 Filter path parameter | ||||
192 | |||||
193 | Any API which returns a JSON body accepts a C<filter_path> parameter | ||||
194 | which will filter the JSON down to only the specified paths. For instance, | ||||
195 | if you are running a search request and only want the C<total> hits and | ||||
196 | the C<_source> field for each hit (without the C<_id>, C<_index> etc), | ||||
197 | you can do: | ||||
198 | |||||
199 | $e->search( | ||||
200 | query => {...}, | ||||
201 | filter_paths => [ 'hits.total', 'hits.hits._source' ] | ||||
202 | ); | ||||
203 | |||||
204 | =head2 Ignore parameter | ||||
205 | |||||
206 | Normally, any HTTP status code outside the 200-299 range will result in | ||||
207 | an error being thrown. To suppress these errors, you can specify which | ||||
208 | status codes to ignore in the C<ignore> parameter. | ||||
209 | |||||
210 | $e->indices->delete( | ||||
211 | index => 'my_index', | ||||
212 | ignore => 404 | ||||
213 | ); | ||||
214 | |||||
215 | This is most useful for | ||||
216 | L<Missing|Search::Elasticsearch::Error/Search::Elasticsearch::Error::Missing> errors, which | ||||
217 | are triggered by a C<404> status code when some requested resource does | ||||
218 | not exist. | ||||
219 | |||||
220 | Multiple error codes can be specified with an array: | ||||
221 | |||||
222 | $e->indices->delete( | ||||
223 | index => 'my_index', | ||||
224 | ignore => [404,409] | ||||
225 | ); | ||||
226 | |||||
227 | =head1 CONFIGURATION | ||||
228 | |||||
229 | =head2 C<bulk_helper_class> | ||||
230 | |||||
231 | The class to use for the L</bulk_helper()> method. Defaults to | ||||
232 | L<Search::Elasticsearch::Bulk>. | ||||
233 | |||||
234 | =head2 C<scroll_helper_class> | ||||
235 | |||||
236 | The class to use for the L</scroll_helper()> method. Defaults to | ||||
237 | L<Search::Elasticsearch::Scroll>. | ||||
238 | |||||
239 | =head1 GENERAL METHODS | ||||
240 | |||||
241 | =head2 C<info()> | ||||
242 | |||||
243 | $info = $e->info | ||||
244 | |||||
245 | Returns information about the version of Elasticsearch that the responding node | ||||
246 | is running. | ||||
247 | |||||
248 | =head2 C<ping()> | ||||
249 | |||||
250 | $e->ping | ||||
251 | |||||
252 | Pings a node in the cluster and returns C<1> if it receives a C<200> | ||||
253 | response, otherwise it throws an error. | ||||
254 | |||||
255 | =head2 C<indices()> | ||||
256 | |||||
257 | $indices_client = $e->indices; | ||||
258 | |||||
259 | Returns an L<Search::Elasticsearch::Client::2_0::Direct::Indices> object which can be used | ||||
260 | for managing indices, eg creating, deleting indices, managing mapping, | ||||
261 | index settings etc. | ||||
262 | |||||
263 | =head2 C<cluster()> | ||||
264 | |||||
265 | $cluster_client = $e->cluster; | ||||
266 | |||||
267 | Returns an L<Search::Elasticsearch::Client::2_0::Direct::Cluster> object which can be used | ||||
268 | for managing the cluster, eg cluster-wide settings and cluster health. | ||||
269 | |||||
270 | =head2 C<nodes()> | ||||
271 | |||||
272 | $node_client = $e->nodes; | ||||
273 | |||||
274 | Returns an L<Search::Elasticsearch::Client::2_0::Direct::Nodes> object which can be used | ||||
275 | to retrieve node info and stats. | ||||
276 | |||||
277 | =head2 C<snapshot()> | ||||
278 | |||||
279 | $snapshot_client = $e->snapshot; | ||||
280 | |||||
281 | Returns an L<Search::Elasticsearch::Client::2_0::Direct::Snapshot> object which | ||||
282 | is used for managing backup repositories and creating and restoring | ||||
283 | snapshots. | ||||
284 | |||||
285 | =head2 C<tasks()> | ||||
286 | |||||
287 | $tasks_client = $e->tasks; | ||||
288 | |||||
289 | Returns an L<Search::Elasticsearch::Client::2_0::Direct::Tasks> object which | ||||
290 | is used for accessing the task management API. | ||||
291 | |||||
292 | =head2 C<cat()> | ||||
293 | |||||
294 | $cat_client = $e->cat; | ||||
295 | |||||
296 | Returns an L<Search::Elasticsearch::Client::2_0::Direct::Cat> object which can be used | ||||
297 | to retrieve simple to read text info for debugging and monitoring an | ||||
298 | Elasticsearch cluster. | ||||
299 | |||||
300 | =head1 DOCUMENT CRUD METHODS | ||||
301 | |||||
302 | These methods allow you to perform create, index, update and delete requests | ||||
303 | for single documents: | ||||
304 | |||||
305 | =head2 C<index()> | ||||
306 | |||||
307 | $response = $e->index( | ||||
308 | index => 'index_name', # required | ||||
309 | type => 'type_name', # required | ||||
310 | id => 'doc_id', # optional, otherwise auto-generated | ||||
311 | |||||
312 | body => { document } # required | ||||
313 | ); | ||||
314 | |||||
315 | The C<index()> method is used to index a new document or to reindex | ||||
316 | an existing document. | ||||
317 | |||||
318 | Query string parameters: | ||||
319 | C<consistency>, | ||||
320 | C<op_type>, | ||||
321 | C<parent>, | ||||
322 | C<refresh>, | ||||
323 | C<routing>, | ||||
324 | C<timeout>, | ||||
325 | C<timestamp>, | ||||
326 | C<ttl>, | ||||
327 | C<version>, | ||||
328 | C<version_type> | ||||
329 | |||||
330 | See the L<index docs|http://www.elastic.co/guide/en/elasticsearch/reference/current/docs-index_.html> | ||||
331 | for more information. | ||||
332 | |||||
333 | =head2 C<create()> | ||||
334 | |||||
335 | $response = $e->create( | ||||
336 | index => 'index_name', # required | ||||
337 | type => 'type_name', # required | ||||
338 | id => 'doc_id', # optional, otherwise auto-generated | ||||
339 | |||||
340 | body => { document } # required | ||||
341 | ); | ||||
342 | |||||
343 | The C<create()> method works exactly like the L</index()> method, except | ||||
344 | that it will throw a C<Conflict> error if a document with the same | ||||
345 | C<index>, C<type> and C<id> already exists. | ||||
346 | |||||
347 | Query string parameters: | ||||
348 | C<consistency>, | ||||
349 | C<op_type>, | ||||
350 | C<parent>, | ||||
351 | C<refresh>, | ||||
352 | C<routing>, | ||||
353 | C<timeout>, | ||||
354 | C<timestamp>, | ||||
355 | C<ttl>, | ||||
356 | C<version>, | ||||
357 | C<version_type> | ||||
358 | |||||
359 | See the L<create docs|http://www.elastic.co/guide/en/elasticsearch/reference/current/docs-create.html> | ||||
360 | for more information. | ||||
361 | |||||
362 | =head2 C<get()> | ||||
363 | |||||
364 | $response = $e->get( | ||||
365 | index => 'index_name', # required | ||||
366 | type => 'type_name', # required | ||||
367 | id => 'doc_id', # required | ||||
368 | ); | ||||
369 | |||||
370 | The C<get()> method will retrieve the document with the specified | ||||
371 | C<index>, C<type> and C<id>, or will throw a C<Missing> error. | ||||
372 | |||||
373 | Query string parameters: | ||||
374 | C<_source>, | ||||
375 | C<_source_exclude>, | ||||
376 | C<_source_include>, | ||||
377 | C<fields>, | ||||
378 | C<parent>, | ||||
379 | C<preference>, | ||||
380 | C<realtime>, | ||||
381 | C<refresh>, | ||||
382 | C<routing>, | ||||
383 | C<version>, | ||||
384 | C<version_type> | ||||
385 | |||||
386 | See the L<get docs|http://www.elastic.co/guide/en/elasticsearch/reference/current/docs-get.html> | ||||
387 | for more information. | ||||
388 | |||||
389 | =head2 C<get_source()> | ||||
390 | |||||
391 | $response = $e->get_source( | ||||
392 | index => 'index_name', # required | ||||
393 | type => 'type_name', # required | ||||
394 | id => 'doc_id', # required | ||||
395 | ); | ||||
396 | |||||
397 | The C<get_source()> method works just like the L</get()> method except that | ||||
398 | it returns just the C<_source> field (the value of the C<body> parameter | ||||
399 | in the L</index()> method) instead of returning the C<_source> field | ||||
400 | plus the document metadata, ie the C<_index>, C<_type> etc. | ||||
401 | |||||
402 | Query string parameters: | ||||
403 | C<_source>, | ||||
404 | C<_source_exclude>, | ||||
405 | C<_source_include>, | ||||
406 | C<parent>, | ||||
407 | C<preference>, | ||||
408 | C<realtime>, | ||||
409 | C<refresh>, | ||||
410 | C<routing>, | ||||
411 | C<version>, | ||||
412 | C<version_type> | ||||
413 | |||||
414 | See the L<get_source docs|http://www.elastic.co/guide/en/elasticsearch/reference/current/docs-get.html> | ||||
415 | for more information. | ||||
416 | |||||
417 | =head2 C<exists()> | ||||
418 | |||||
419 | $response = $e->exists( | ||||
420 | index => 'index_name', # required | ||||
421 | type => 'type_name', # required | ||||
422 | id => 'doc_id', # required | ||||
423 | ); | ||||
424 | |||||
425 | The C<exists()> method returns C<1> if a document with the specified | ||||
426 | C<index>, C<type> and C<id> exists, or an empty string if it doesn't. | ||||
427 | |||||
428 | Query string parameters: | ||||
429 | C<parent>, | ||||
430 | C<preference>, | ||||
431 | C<realtime>, | ||||
432 | C<refresh>, | ||||
433 | C<routing> | ||||
434 | |||||
435 | See the L<exists docs|http://www.elastic.co/guide/en/elasticsearch/reference/current/docs-get.html> | ||||
436 | for more information. | ||||
437 | |||||
438 | =head2 C<delete()> | ||||
439 | |||||
440 | $response = $e->delete( | ||||
441 | index => 'index_name', # required | ||||
442 | type => 'type_name', # required | ||||
443 | id => 'doc_id', # required | ||||
444 | ); | ||||
445 | |||||
446 | The C<delete()> method will delete the document with the specified | ||||
447 | C<index>, C<type> and C<id>, or will throw a C<Missing> error. | ||||
448 | |||||
449 | Query string parameters: | ||||
450 | C<consistency>, | ||||
451 | C<parent>, | ||||
452 | C<refresh>, | ||||
453 | C<routing>, | ||||
454 | C<timeout>, | ||||
455 | C<version>, | ||||
456 | C<version_type> | ||||
457 | |||||
458 | See the L<delete docs|http://www.elastic.co/guide/en/elasticsearch/reference/current/docs-delete.html> | ||||
459 | for more information. | ||||
460 | |||||
461 | =head2 C<update()> | ||||
462 | |||||
463 | $response = $e->update( | ||||
464 | index => 'index_name', # required | ||||
465 | type => 'type_name', # required | ||||
466 | id => 'doc_id', # required | ||||
467 | |||||
468 | body => { update } # required | ||||
469 | ); | ||||
470 | |||||
471 | The C<update()> method updates a document with the corresponding | ||||
472 | C<index>, C<type> and C<id> if it exists. Updates can be performed either by: | ||||
473 | |||||
474 | =over | ||||
475 | |||||
476 | =item * providing a partial document to be merged in to the existing document: | ||||
477 | |||||
478 | $response = $e->update( | ||||
479 | ..., | ||||
480 | body => { | ||||
481 | doc => { new_field => 'new_value'}, | ||||
482 | } | ||||
483 | ); | ||||
484 | |||||
485 | =item * with an inline script: | ||||
486 | |||||
487 | $response = $e->update( | ||||
488 | ..., | ||||
489 | body => { | ||||
490 | script => { | ||||
491 | inline => "ctx._source.counter += incr", | ||||
492 | params => { incr => 5 } | ||||
493 | } | ||||
494 | } | ||||
495 | ); | ||||
496 | |||||
497 | Make sure you enable | ||||
498 | L<dynamic scripting|https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-scripting.html#enable-dynamic-scripting> | ||||
499 | and know its implications. | ||||
500 | |||||
501 | =item * with an indexed script: | ||||
502 | |||||
503 | $response = $e->update( | ||||
504 | ..., | ||||
505 | body => { | ||||
506 | script => { | ||||
507 | id => $id, | ||||
508 | params => { incr => 5 } | ||||
509 | } | ||||
510 | } | ||||
511 | ); | ||||
512 | |||||
513 | See L<indexed scripts|https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-scripting.html#_indexed_scripts> | ||||
514 | for more information. | ||||
515 | |||||
516 | =item * with a script stored as a file: | ||||
517 | |||||
518 | $response = $e->update( | ||||
519 | ..., | ||||
520 | body => { | ||||
521 | script => { | ||||
522 | file => 'counter', | ||||
523 | lang => 'groovy', | ||||
524 | params => { incr => 5 } | ||||
525 | } | ||||
526 | } | ||||
527 | ); | ||||
528 | |||||
529 | See L<scripting docs|https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-scripting.html> | ||||
530 | for more information. | ||||
531 | |||||
532 | =back | ||||
533 | |||||
534 | Query string parameters: | ||||
535 | C<consistency>, | ||||
536 | C<detect_noop>, | ||||
537 | C<fields>, | ||||
538 | C<lang>, | ||||
539 | C<parent>, | ||||
540 | C<realtime>, | ||||
541 | C<refresh>, | ||||
542 | C<retry_on_conflict>, | ||||
543 | C<routing>, | ||||
544 | C<script>, | ||||
545 | C<script_id>, | ||||
546 | C<scripted_upsert>, | ||||
547 | C<timeout>, | ||||
548 | C<timestamp>, | ||||
549 | C<ttl>, | ||||
550 | C<version>, | ||||
551 | C<version_type> | ||||
552 | |||||
553 | See the L<update docs|http://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update.html> | ||||
554 | for more information. | ||||
555 | |||||
556 | =head2 C<termvectors()> | ||||
557 | |||||
558 | $results = $e->termvectors( | ||||
559 | index => $index, # required | ||||
560 | type => $type, # required | ||||
561 | |||||
562 | id => $id, # optional | ||||
563 | body => {...} # optional | ||||
564 | ) | ||||
565 | |||||
566 | The C<termvectors()> method retrieves term and field statistics, positions, | ||||
567 | offsets and payloads for the specified document, assuming that termvectors | ||||
568 | have been enabled. | ||||
569 | |||||
570 | Query string parameters: | ||||
571 | C<dfs>, | ||||
572 | C<field_statistics>, | ||||
573 | C<fields>, | ||||
574 | C<offsets>, | ||||
575 | C<parent>, | ||||
576 | C<payloads>, | ||||
577 | C<positions>, | ||||
578 | C<preference>, | ||||
579 | C<realtime>, | ||||
580 | C<routing>, | ||||
581 | C<term_statistics>, | ||||
582 | C<version>, | ||||
583 | C<version_type> | ||||
584 | |||||
585 | See the L<termvector docs|http://www.elastic.co/guide/en/elasticsearch/reference/current/docs-termvectors.html> | ||||
586 | for more information. | ||||
587 | |||||
588 | =head1 BULK DOCUMENT CRUD METHODS | ||||
589 | |||||
590 | The bulk document CRUD methods are used for running multiple CRUD actions | ||||
591 | within a single request. By reducing the number of network requests | ||||
592 | that need to be made, bulk requests greatly improve performance. | ||||
593 | |||||
594 | =head2 C<bulk()> | ||||
595 | |||||
596 | $response = $e->bulk( | ||||
597 | index => 'index_name', # required if type specified | ||||
598 | type => 'type_name', # optional | ||||
599 | |||||
600 | body => [ actions ] # required | ||||
601 | ); | ||||
602 | |||||
603 | See L<Search::Elasticsearch::Bulk> and L</bulk_helper()> for a helper module that makes | ||||
604 | bulk indexing simpler to use. | ||||
605 | |||||
606 | The C<bulk()> method can perform multiple L</index()>, L</create()>, | ||||
607 | L</delete()> or L</update()> actions with a single request. The C<body> | ||||
608 | parameter expects an array containing the list of actions to perform. | ||||
609 | |||||
610 | An I<action> consists of an initial metadata hash ref containing the action | ||||
611 | type, plus the associated metadata, eg : | ||||
612 | |||||
613 | { delete => { _index => 'index', _type => 'type', _id => 123 }} | ||||
614 | |||||
615 | The C<index> and C<create> actions then expect a hashref containing | ||||
616 | the document itself: | ||||
617 | |||||
618 | { create => { _index => 'index', _type => 'type', _id => 123 }}, | ||||
619 | { title => "A newly created document" } | ||||
620 | |||||
621 | And the C<update> action expects a hashref containing the update commands, | ||||
622 | eg: | ||||
623 | |||||
624 | { update => { _index => 'index', _type => 'type', _id => 123 }}, | ||||
625 | { script => "ctx._source.counter+=1" } | ||||
626 | |||||
627 | Each action can include the same parameters that you would pass to | ||||
628 | the equivalent L</index()>, L</create()>, L</delete()> or L</update()> | ||||
629 | request, except that C<_index>, C<_type> and C<_id> must be specified with | ||||
630 | the preceding underscore. All other parameters can be specified with or | ||||
631 | without the underscore. | ||||
632 | |||||
633 | For instance: | ||||
634 | |||||
635 | $response = $e->bulk( | ||||
636 | index => 'index_name', # default index name | ||||
637 | type => 'type_name', # default type name | ||||
638 | body => [ | ||||
639 | |||||
640 | # create action | ||||
641 | { create => { | ||||
642 | _index => 'not_the_default_index', | ||||
643 | _type => 'not_the_default_type', | ||||
644 | _id => 123 | ||||
645 | }}, | ||||
646 | { title => 'Foo' }, | ||||
647 | |||||
648 | # index action | ||||
649 | { index => { _id => 124 }}, | ||||
650 | { title => 'Foo' }, | ||||
651 | |||||
652 | # delete action | ||||
653 | { delete => { _id => 125 }}, | ||||
654 | |||||
655 | # update action | ||||
656 | { update => { _id => 126 }}, | ||||
657 | { script => "ctx._source.counter+1" } | ||||
658 | ] | ||||
659 | ); | ||||
660 | |||||
661 | Each action is performed separately. One failed action will not | ||||
662 | cause the others to fail as well. | ||||
663 | |||||
664 | Query string parameters: | ||||
665 | C<consistency>, | ||||
666 | C<fields>, | ||||
667 | C<refresh>, | ||||
668 | C<routing>, | ||||
669 | C<timeout> | ||||
670 | |||||
671 | See the L<bulk docs|http://www.elastic.co/guide/en/elasticsearch/reference/current/docs-bulk.html> | ||||
672 | for more information. | ||||
673 | |||||
674 | =head2 C<bulk_helper()> | ||||
675 | |||||
676 | $bulk_helper = $e->bulk_helper( @args ); | ||||
677 | |||||
678 | Returns a new instance of the class specified in the L</bulk_helper_class>, | ||||
679 | which defaults to L<Search::Elasticsearch::Bulk>. | ||||
680 | |||||
681 | =head2 C<mget()> | ||||
682 | |||||
683 | $results = $e->mget( | ||||
684 | index => 'default_index', # optional, required when type specified | ||||
685 | type => 'default_type', # optional | ||||
686 | |||||
687 | body => { docs or ids } # required | ||||
688 | ); | ||||
689 | |||||
690 | The C<mget()> method will retrieve multiple documents with a single request. | ||||
691 | The C<body> consists of an array of documents to retrieve: | ||||
692 | |||||
693 | $results = $e->mget( | ||||
694 | index => 'default_index', | ||||
695 | type => 'default_type', | ||||
696 | body => { | ||||
697 | docs => [ | ||||
698 | { _id => 1}, | ||||
699 | { _id => 2, _type => 'not_the_default_type' } | ||||
700 | ] | ||||
701 | } | ||||
702 | ); | ||||
703 | |||||
704 | You can also pass any of the other parameters that the L</get()> request | ||||
705 | accepts. | ||||
706 | |||||
707 | If you have specified an C<index> and C<type>, you can just include the | ||||
708 | C<ids> of the documents to retrieve: | ||||
709 | |||||
710 | $results = $e->mget( | ||||
711 | index => 'default_index', | ||||
712 | type => 'default_type', | ||||
713 | body => { | ||||
714 | ids => [ 1, 2, 3] | ||||
715 | } | ||||
716 | ); | ||||
717 | |||||
718 | Query string parameters: | ||||
719 | C<_source>, | ||||
720 | C<_source_exclude>, | ||||
721 | C<_source_include>, | ||||
722 | C<fields>, | ||||
723 | C<preference>, | ||||
724 | C<realtime>, | ||||
725 | C<refresh> | ||||
726 | |||||
727 | See the L<mget docs|http://www.elastic.co/guide/en/elasticsearch/reference/current/docs-multi-get.html> | ||||
728 | for more information. | ||||
729 | |||||
730 | =head2 C<mtermvectors()> | ||||
731 | |||||
732 | $results = $e->mtermvectors( | ||||
733 | index => $index, # required if type specified | ||||
734 | type => $type, # optional | ||||
735 | |||||
736 | body => { } # optional | ||||
737 | ) | ||||
738 | |||||
739 | Runs multiple L</termvector()> requests in a single request, eg: | ||||
740 | |||||
741 | $results = $e->mtermvectors( | ||||
742 | index => 'test', | ||||
743 | body => { | ||||
744 | docs => [ | ||||
745 | { _type => 'test', _id => 1, fields => ['text'] }, | ||||
746 | { _type => 'test', _id => 2, payloads => 1 }, | ||||
747 | ] | ||||
748 | } | ||||
749 | ); | ||||
750 | |||||
751 | Query string parameters: | ||||
752 | C<field_statistics>, | ||||
753 | C<fields>, | ||||
754 | C<ids>, | ||||
755 | C<offsets>, | ||||
756 | C<parent>, | ||||
757 | C<payloads>, | ||||
758 | C<positions>, | ||||
759 | C<preference>, | ||||
760 | C<realtime>, | ||||
761 | C<routing>, | ||||
762 | C<term_statistics>, | ||||
763 | C<version>, | ||||
764 | C<version_type> | ||||
765 | |||||
766 | See the L<mtermvectors docs|http://www.elastic.co/guide/en/elasticsearch/reference/current/docs-multi-termvectors.html> | ||||
767 | for more information. | ||||
768 | |||||
769 | =head1 SEARCH METHODS | ||||
770 | |||||
771 | The search methods are used for querying documents in one, more or all indices | ||||
772 | and of one, more or all types: | ||||
773 | |||||
774 | =head2 C<search()> | ||||
775 | |||||
776 | $results = $e->search( | ||||
777 | index => 'index' | \@indices, # optional | ||||
778 | type => 'type' | \@types, # optional | ||||
779 | |||||
780 | body => { search params } # optional | ||||
781 | ); | ||||
782 | |||||
783 | The C<search()> method searches for matching documents in one or more | ||||
784 | indices. It is just as easy to search a single index as it is to search | ||||
785 | all the indices in your cluster. It can also return | ||||
786 | L<aggregations|http://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations.html> | ||||
787 | L<highlighted snippets|http://www.elastic.co/guide/en/elasticsearch/reference/current/search-highlighting.html> | ||||
788 | and L<did-you-mean|http://www.elastic.co/guide/en/elasticsearch/reference/current/search-suggesters-phrase.html> | ||||
789 | or L<search-as-you-type|http://www.elastic.co/guide/en/elasticsearch/reference/current/search-suggesters-completion.html> | ||||
790 | suggestions. | ||||
791 | |||||
792 | The I<lite> L<version of search|http://www.elastic.co/guide/en/elasticsearch/reference/current/search-uri-request.html> | ||||
793 | allows you to specify a query string in the C<q> parameter, using the | ||||
794 | Lucene query string syntax: | ||||
795 | |||||
796 | $results = $e->search( q => 'title:(elasticsearch clients)'); | ||||
797 | |||||
798 | However, the preferred way to search is by using the | ||||
799 | L<Query DSL|http://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl.html> | ||||
800 | to create a query, and passing that C<query> in the | ||||
801 | L<request body|http://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-body.html>: | ||||
802 | |||||
803 | $results = $e->search( | ||||
804 | body => { | ||||
805 | query => { | ||||
806 | match => { title => 'Elasticsearch clients'} | ||||
807 | } | ||||
808 | } | ||||
809 | ); | ||||
810 | |||||
811 | Query string parameters: | ||||
812 | C<_source>, | ||||
813 | C<_source_exclude>, | ||||
814 | C<_source_include>, | ||||
815 | C<allow_no_indices>, | ||||
816 | C<analyze_wildcard>, | ||||
817 | C<analyzer>, | ||||
818 | C<default_operator>, | ||||
819 | C<df>, | ||||
820 | C<expand_wildcards>, | ||||
821 | C<explain>, | ||||
822 | C<fielddata_fields>, | ||||
823 | C<fields>, | ||||
824 | C<from>, | ||||
825 | C<ignore_unavailable>, | ||||
826 | C<lenient>, | ||||
827 | C<lowercase_expanded_terms>, | ||||
828 | C<preference>, | ||||
829 | C<q>, | ||||
830 | C<request_cache>, | ||||
831 | C<routing>, | ||||
832 | C<scroll>, | ||||
833 | C<search_type>, | ||||
834 | C<size>, | ||||
835 | C<sort>, | ||||
836 | C<stats>, | ||||
837 | C<suggest_field>, | ||||
838 | C<suggest_mode>, | ||||
839 | C<suggest_size>, | ||||
840 | C<suggest_text>, | ||||
841 | C<terminate_after>, | ||||
842 | C<timeout>, | ||||
843 | C<track_scores>, | ||||
844 | C<version> | ||||
845 | |||||
846 | See the L<search reference|http://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-body.html> | ||||
847 | for more information. | ||||
848 | |||||
849 | Also see L<Search::Elasticsearch::Transport/send_get_body_as>. | ||||
850 | |||||
851 | =head2 C<search_exists()> | ||||
852 | |||||
853 | The C<search_exists()> method is a quick version of search which can be | ||||
854 | used to find out whether there are matching search results or not. | ||||
855 | It doesn't return any results itself. | ||||
856 | |||||
857 | $results = $e->search_exists( | ||||
858 | index => 'index' | \@indices, # optional | ||||
859 | type => 'type' | \@types, # optional | ||||
860 | |||||
861 | body => { search params } # optional | ||||
862 | ); | ||||
863 | |||||
864 | Query string parameters: | ||||
865 | C<allow_no_indices>, | ||||
866 | C<analyze_wildcard>, | ||||
867 | C<analyzer>, | ||||
868 | C<default_operator>, | ||||
869 | C<df>, | ||||
870 | C<expand_wildcards>, | ||||
871 | C<ignore_unavailable>, | ||||
872 | C<lenient>, | ||||
873 | C<lowercase_expanded_terms> | ||||
874 | C<min_score>, | ||||
875 | C<preference>, | ||||
876 | C<q>, | ||||
877 | C<routing> | ||||
878 | |||||
879 | See the L<search exists reference|http://www.elastic.co/guide/en/elasticsearch/reference/current/search-exists.html> | ||||
880 | for more information. | ||||
881 | |||||
882 | =head2 C<count()> | ||||
883 | |||||
884 | $results = $e->count( | ||||
885 | index => 'index' | \@indices, # optional | ||||
886 | type => 'type' | \@types, # optional | ||||
887 | |||||
888 | body => { query } # optional | ||||
889 | ) | ||||
890 | |||||
891 | The C<count()> method returns the total count of all documents matching the | ||||
892 | query: | ||||
893 | |||||
894 | $results = $e->count( | ||||
895 | body => { | ||||
896 | query => { | ||||
897 | match => { title => 'Elasticsearch clients' } | ||||
898 | } | ||||
899 | } | ||||
900 | ); | ||||
901 | |||||
902 | Query string parameters: | ||||
903 | C<allow_no_indices>, | ||||
904 | C<analyze_wildcard>, | ||||
905 | C<analyzer>, | ||||
906 | C<default_operator>, | ||||
907 | C<df>, | ||||
908 | C<expand_wildcards>, | ||||
909 | C<ignore_unavailable>, | ||||
910 | C<lenient>, | ||||
911 | C<lowercase_expanded_terms> | ||||
912 | C<min_score>, | ||||
913 | C<preference>, | ||||
914 | C<q>, | ||||
915 | C<routing> | ||||
916 | |||||
917 | See the L<count docs|http://www.elastic.co/guide/en/elasticsearch/reference/current/search-count.html> | ||||
918 | for more information. | ||||
919 | |||||
920 | =head2 C<search_template()> | ||||
921 | |||||
922 | $results = $e->search_template( | ||||
923 | index => 'index' | \@indices, # optional | ||||
924 | type => 'type' | \@types, # optional | ||||
925 | |||||
926 | body => { search params } # optional | ||||
927 | ); | ||||
928 | |||||
929 | Perform a search by specifying a template (either predefined or defined | ||||
930 | within the C<body>) and parameters to use with the template, eg: | ||||
931 | |||||
932 | $results = $e->search_template( | ||||
933 | body => { | ||||
934 | inline => { | ||||
935 | query => { | ||||
936 | match => { | ||||
937 | "{{my_field}}" => "{{my_value}}" | ||||
938 | } | ||||
939 | }, | ||||
940 | size => "{{my_size}}" | ||||
941 | }, | ||||
942 | params => { | ||||
943 | my_field => 'foo', | ||||
944 | my_value => 'bar', | ||||
945 | my_size => 5 | ||||
946 | } | ||||
947 | } | ||||
948 | ); | ||||
949 | |||||
950 | See the L<search template docs|http://www.elastic.co/guide/en/elasticsearch/reference/current/search-template.html> | ||||
951 | for more information. | ||||
952 | |||||
953 | Query string parameters: | ||||
954 | C<allow_no_indices>, | ||||
955 | C<expand_wildcards>, | ||||
956 | C<ignore_unavailable>, | ||||
957 | C<preference>, | ||||
958 | C<scroll>, | ||||
959 | C<search_type> | ||||
960 | |||||
961 | =head2 C<render_search_template()> | ||||
962 | |||||
963 | $response = $e->render_search_template( | ||||
964 | id => 'id', # optional | ||||
965 | body => { template } # optional | ||||
966 | ); | ||||
967 | |||||
968 | Renders the template, filling in the passed-in parameters and returns the resulting JSON, eg: | ||||
969 | |||||
970 | $results = $e->render_search_template( | ||||
971 | body => { | ||||
972 | inline => { | ||||
973 | query => { | ||||
974 | match => { | ||||
975 | "{{my_field}}" => "{{my_value}}" | ||||
976 | } | ||||
977 | }, | ||||
978 | size => "{{my_size}}" | ||||
979 | }, | ||||
980 | params => { | ||||
981 | my_field => 'foo', | ||||
982 | my_value => 'bar', | ||||
983 | my_size => 5 | ||||
984 | } | ||||
985 | } | ||||
986 | ); | ||||
987 | |||||
988 | See the L<search template docs|http://www.elastic.co/guide/en/elasticsearch/reference/current/search-template.html> | ||||
989 | for more information. | ||||
990 | |||||
991 | =head2 C<scroll()> | ||||
992 | |||||
993 | $results = $e->scroll( | ||||
994 | scroll => '1m', | ||||
995 | scroll_id => $id | ||||
996 | ); | ||||
997 | |||||
998 | When a L</search()> has been performed with the | ||||
999 | C<scroll> parameter, the C<scroll()> | ||||
1000 | method allows you to keep pulling more results until the results | ||||
1001 | are exhausted. | ||||
1002 | |||||
1003 | B<NOTE:> you will almost always want to set the | ||||
1004 | C<search_type> to C<scan> in your | ||||
1005 | original C<search()> request. | ||||
1006 | |||||
1007 | See L</scroll_helper()> and L<Search::Elasticsearch::Scroll> for a helper utility | ||||
1008 | which makes managing scroll requests much easier. | ||||
1009 | |||||
1010 | Query string parameters: | ||||
1011 | C<scroll>, | ||||
1012 | C<scroll_id> | ||||
1013 | |||||
1014 | See the L<scroll docs|http://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-scroll.html> | ||||
1015 | and the L<search_type docs|http://www.elastic.co/guide/en/elasticsearch/reference/current/search.html/search-request-search-type.html> | ||||
1016 | for more information. | ||||
1017 | |||||
1018 | =head2 C<clear_scroll()> | ||||
1019 | |||||
1020 | $response = $e->clear_scroll( | ||||
1021 | scroll_id => $id | \@ids # required | ||||
1022 | ); | ||||
1023 | |||||
1024 | Or | ||||
1025 | |||||
1026 | $response = $e->clear_scroll( | ||||
1027 | body => $id | ||||
1028 | ); | ||||
1029 | |||||
1030 | The C<clear_scroll()> method can clear unfinished scroll requests, freeing | ||||
1031 | up resources on the server. | ||||
1032 | |||||
1033 | =head2 C<scroll_helper()> | ||||
1034 | |||||
1035 | $scroll_helper = $e->scroll_helper( @args ); | ||||
1036 | |||||
1037 | Returns a new instance of the class specified in the L</scroll_helper_class>, | ||||
1038 | which defaults to L<Search::Elasticsearch::Scroll>. | ||||
1039 | |||||
1040 | =head2 C<msearch()> | ||||
1041 | |||||
1042 | $results = $e->msearch( | ||||
1043 | index => 'default_index' | \@indices, # optional | ||||
1044 | type => 'default_type' | \@types, # optional | ||||
1045 | |||||
1046 | body => [ searches ] # required | ||||
1047 | ); | ||||
1048 | |||||
1049 | The C<msearch()> method allows you to perform multiple searches in a single | ||||
1050 | request. Similar to the L</bulk()> request, each search request in the | ||||
1051 | C<body> consists of two hashes: the metadata hash then the search request | ||||
1052 | hash (the same data that you'd specify in the C<body> of a L</search()> | ||||
1053 | request). For instance: | ||||
1054 | |||||
1055 | $results = $e->msearch( | ||||
1056 | index => 'default_index', | ||||
1057 | type => ['default_type_1', 'default_type_2'], | ||||
1058 | body => [ | ||||
1059 | # uses defaults | ||||
1060 | {}, | ||||
1061 | { query => { match_all => {} }}, | ||||
1062 | |||||
1063 | # uses a custom index | ||||
1064 | { index => 'not_the_default_index' }, | ||||
1065 | { query => { match_all => {} }} | ||||
1066 | ] | ||||
1067 | ); | ||||
1068 | |||||
1069 | Query string parameters: | ||||
1070 | C<search_type> | ||||
1071 | |||||
1072 | See the L<msearch docs|http://www.elastic.co/guide/en/elasticsearch/reference/current/search-multi-search.html> | ||||
1073 | for more information. | ||||
1074 | |||||
1075 | =head2 C<explain()> | ||||
1076 | |||||
1077 | $response = $e->explain( | ||||
1078 | index => 'my_index', # required | ||||
1079 | type => 'my_type', # required | ||||
1080 | id => 123, # required | ||||
1081 | |||||
1082 | body => { search } # required | ||||
1083 | ); | ||||
1084 | |||||
1085 | The C<explain()> method explains why the specified document did or | ||||
1086 | did not match a query, and how the relevance score was calculated. | ||||
1087 | For instance: | ||||
1088 | |||||
1089 | $response = $e->explain( | ||||
1090 | index => 'my_index', | ||||
1091 | type => 'my_type', | ||||
1092 | id => 123, | ||||
1093 | body => { | ||||
1094 | query => { | ||||
1095 | match => { title => 'Elasticsearch clients' } | ||||
1096 | } | ||||
1097 | } | ||||
1098 | ); | ||||
1099 | |||||
1100 | Query string parameters: | ||||
1101 | C<_source>, | ||||
1102 | C<_source_exclude>, | ||||
1103 | C<_source_include>, | ||||
1104 | C<analyze_wildcard>, | ||||
1105 | C<analyzer>, | ||||
1106 | C<default_operator>, | ||||
1107 | C<df>, | ||||
1108 | C<fields>, | ||||
1109 | C<lenient>, | ||||
1110 | C<lowercase_expanded_terms>, | ||||
1111 | C<parent>, | ||||
1112 | C<preference>, | ||||
1113 | C<q>, | ||||
1114 | C<routing> | ||||
1115 | |||||
1116 | See the L<explain docs|http://www.elastic.co/guide/en/elasticsearch/reference/current/search-explain.html> | ||||
1117 | for more information. | ||||
1118 | |||||
1119 | =head2 C<field_stats()> | ||||
1120 | |||||
1121 | $response = $e->field_stats( | ||||
1122 | index => 'index' | \@indices, # optional | ||||
1123 | fields => 'field' | \@fields, # optional | ||||
1124 | level => 'cluster' | 'indices', # optional | ||||
1125 | body => { filters } # optional | ||||
1126 | ); | ||||
1127 | |||||
1128 | The C<field-stats> API returns statistical properties of a field | ||||
1129 | (such as min and max values) without executing a search. | ||||
1130 | |||||
1131 | Query string parameters: | ||||
1132 | C<allow_no_indices>, | ||||
1133 | C<expand_wildcards>, | ||||
1134 | C<fields>, | ||||
1135 | C<ignore_unavailable>, | ||||
1136 | C<level> | ||||
1137 | |||||
1138 | See the L<field-stats docs|http://www.elastic.co/guide/en/elasticsearch/reference/current/search-field-stats.html> | ||||
1139 | for more information. | ||||
1140 | |||||
1141 | =head2 C<search_shards()> | ||||
1142 | |||||
1143 | $response = $e->search_shards( | ||||
1144 | index => 'index' | \@indices, # optional | ||||
1145 | type => 'type' | \@types, # optional | ||||
1146 | ) | ||||
1147 | |||||
1148 | The C<search_shards()> method returns information about which shards on | ||||
1149 | which nodes will execute a search request. | ||||
1150 | |||||
1151 | Query string parameters: | ||||
1152 | C<allow_no_indices>, | ||||
1153 | C<expand_wildcards>, | ||||
1154 | C<ignore_unavailable>, | ||||
1155 | C<local>, | ||||
1156 | C<preference>, | ||||
1157 | C<routing> | ||||
1158 | |||||
1159 | See the L<search-shards docs|http://www.elastic.co/guide/en/elasticsearch/reference/current/search-shards.html> | ||||
1160 | for more information. | ||||
1161 | |||||
1162 | =head1 CRUD-BY-QUERY METHODS | ||||
1163 | |||||
1164 | =head2 C<delete_by_query()> | ||||
1165 | |||||
1166 | $response = $e->delete_by_query( | ||||
1167 | index => 'index' | \@indices, # optional | ||||
1168 | type => 'type' | \@types, # optional, | ||||
1169 | body => { delete-by-query } # optional | ||||
1170 | ); | ||||
1171 | |||||
1172 | The C<delete_by_query()> method (available with the | ||||
1173 | L<delete-by-query plugin|https://www.elastic.co/guide/en/elasticsearch/plugins/current/plugins-delete-by-query.html>) | ||||
1174 | deletes all documents which match the specified query. | ||||
1175 | |||||
1176 | Query string parameters: | ||||
1177 | C<allow_no_indices>, | ||||
1178 | C<analyzer>, | ||||
1179 | C<default_operator>, | ||||
1180 | C<df>, | ||||
1181 | C<expand_wildcards>, | ||||
1182 | C<filter_path>, | ||||
1183 | C<ignore_unavailable>, | ||||
1184 | C<q>, | ||||
1185 | C<routing>, | ||||
1186 | C<timeout> | ||||
1187 | |||||
1188 | See the L<delete-by-query docs|https://www.elastic.co/guide/en/elasticsearch/plugins/current/plugins-delete-by-query.html> | ||||
1189 | for more information. | ||||
1190 | |||||
1191 | =head2 C<reindex()> | ||||
1192 | |||||
1193 | $response = $e->reindex( | ||||
1194 | body => { reindex } # required | ||||
1195 | ); | ||||
1196 | |||||
1197 | The C<reindex()> API is used to index documents from one index or multiple indices | ||||
1198 | to a new index. | ||||
1199 | |||||
1200 | Query string parameters: | ||||
1201 | C<consistency>, | ||||
1202 | C<refresh>, | ||||
1203 | C<timeout>, | ||||
1204 | C<wait_for_completion> | ||||
1205 | |||||
1206 | See the L<reindex docs|https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-reindex.html> | ||||
1207 | for more information. | ||||
1208 | |||||
1209 | =head2 C<update_by_query()> | ||||
1210 | |||||
1211 | $response = $e->update_by_query( | ||||
1212 | index => 'index' | \@indices, # optional | ||||
1213 | type => 'type' | \@types, # optional, | ||||
1214 | body => { update-by-query } # optional | ||||
1215 | ); | ||||
1216 | |||||
1217 | The C<update_by_query()> API is used to bulk update documents from one index or | ||||
1218 | multiple indices using a script. | ||||
1219 | |||||
1220 | Query string parameters: | ||||
1221 | C<_source>, | ||||
1222 | C<_source_exclude>, | ||||
1223 | C<_source_include>, | ||||
1224 | C<allow_no_indices>, | ||||
1225 | C<analyze_wildcard>, | ||||
1226 | C<analyzer>, | ||||
1227 | C<conflicts>, | ||||
1228 | C<consistency>, | ||||
1229 | C<default_operator>, | ||||
1230 | C<df>, | ||||
1231 | C<expand_wildcards>, | ||||
1232 | C<explain>, | ||||
1233 | C<fielddata_fields>, | ||||
1234 | C<fields>, | ||||
1235 | C<from>, | ||||
1236 | C<ignore_unavailable>, | ||||
1237 | C<lenient>, | ||||
1238 | C<lowercase_expanded_terms>, | ||||
1239 | C<preference>, | ||||
1240 | C<q>, | ||||
1241 | C<refresh>, | ||||
1242 | C<request_cache>, | ||||
1243 | C<routing>, | ||||
1244 | C<scroll>, | ||||
1245 | C<scroll_size>, | ||||
1246 | C<search_timeout>, | ||||
1247 | C<search_type>, | ||||
1248 | C<size>, | ||||
1249 | C<sort>, | ||||
1250 | C<stats>, | ||||
1251 | C<suggest_field>, | ||||
1252 | C<suggest_mode>, | ||||
1253 | C<suggest_size>, | ||||
1254 | C<suggest_text>, | ||||
1255 | C<terminate_after>, | ||||
1256 | C<timeout>, | ||||
1257 | C<track_scores>, | ||||
1258 | C<version>, | ||||
1259 | C<version_type>, | ||||
1260 | C<wait_for_completion> | ||||
1261 | |||||
1262 | See the L<update_by_query docs|https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update-by-query.html> | ||||
1263 | for more information. | ||||
1264 | |||||
1265 | =head1 PERCOLATION METHODS | ||||
1266 | |||||
1267 | =head2 C<percolate()> | ||||
1268 | |||||
1269 | $results = $e->percolate( | ||||
1270 | index => 'my_index', # required | ||||
1271 | type => 'my_type', # required | ||||
1272 | |||||
1273 | body => { percolation } # required | ||||
1274 | ); | ||||
1275 | |||||
1276 | Percolation is search inverted: instead of finding docs which match a | ||||
1277 | particular query, it finds queries which match a particular document, eg | ||||
1278 | for I<alert-me-when> functionality. | ||||
1279 | |||||
1280 | The C<percolate()> method runs a percolation request to find the | ||||
1281 | queries matching a particular document. In the C<body> you should pass the | ||||
1282 | C<_source> field of the document under the C<doc> key: | ||||
1283 | |||||
1284 | $results = $e->percolate( | ||||
1285 | index => 'my_index', | ||||
1286 | type => 'my_type', | ||||
1287 | body => { | ||||
1288 | doc => { | ||||
1289 | title => 'Elasticsearch rocks' | ||||
1290 | } | ||||
1291 | } | ||||
1292 | ); | ||||
1293 | |||||
1294 | Query string parameters: | ||||
1295 | C<allow_no_indices>, | ||||
1296 | C<expand_wildcards>, | ||||
1297 | C<ignore_unavailable>, | ||||
1298 | C<percolate_format>, | ||||
1299 | C<percolate_index>, | ||||
1300 | C<percolate_preference>, | ||||
1301 | C<percolate_routing>, | ||||
1302 | C<percolate_type>, | ||||
1303 | C<preference>, | ||||
1304 | C<routing>, | ||||
1305 | C<version>, | ||||
1306 | C<version_type> | ||||
1307 | |||||
1308 | See the L<percolate docs|http://www.elastic.co/guide/en/elasticsearch/reference/current/search-percolate.html> | ||||
1309 | for more information. | ||||
1310 | |||||
1311 | =head2 C<count_percolate()> | ||||
1312 | |||||
1313 | $results = $e->count_percolate( | ||||
1314 | index => 'my_index', # required | ||||
1315 | type => 'my_type', # required | ||||
1316 | |||||
1317 | body => { percolation } # required | ||||
1318 | ); | ||||
1319 | |||||
1320 | The L</count_percolate()> request works just like the L</percolate()> | ||||
1321 | request except that it returns a count of all matching queries, instead | ||||
1322 | of the queries themselves. | ||||
1323 | |||||
1324 | $results = $e->count_percolate( | ||||
1325 | index => 'my_index', | ||||
1326 | type => 'my_type', | ||||
1327 | body => { | ||||
1328 | doc => { | ||||
1329 | title => 'Elasticsearch rocks' | ||||
1330 | } | ||||
1331 | } | ||||
1332 | ); | ||||
1333 | |||||
1334 | Query string parameters: | ||||
1335 | C<allow_no_indices>, | ||||
1336 | C<expand_wildcards>, | ||||
1337 | C<ignore_unavailable>, | ||||
1338 | C<percolate_index>, | ||||
1339 | C<percolate_type>, | ||||
1340 | C<preference>, | ||||
1341 | C<routing>, | ||||
1342 | C<version>, | ||||
1343 | C<version_type> | ||||
1344 | |||||
1345 | See the L<percolate docs|http://www.elastic.co/guide/en/elasticsearch/reference/current/search-percolate.html> | ||||
1346 | for more information. | ||||
1347 | |||||
1348 | =head2 C<mpercolate()> | ||||
1349 | |||||
1350 | $results = $e->mpercolate( | ||||
1351 | index => 'my_index', # required if type | ||||
1352 | type => 'my_type', # optional | ||||
1353 | |||||
1354 | body => [ percolation requests ] # required | ||||
1355 | ); | ||||
1356 | |||||
1357 | Multi-percolation allows multiple L</percolate()> requests to be run | ||||
1358 | in a single request. | ||||
1359 | |||||
1360 | $results = $e->mpercolate( | ||||
1361 | index => 'my_index', | ||||
1362 | type => 'my_type', | ||||
1363 | body => [ | ||||
1364 | # first request | ||||
1365 | { percolate => { | ||||
1366 | index => 'twitter', | ||||
1367 | type => 'tweet' | ||||
1368 | }}, | ||||
1369 | { doc => {message => 'some_text' }}, | ||||
1370 | |||||
1371 | # second request | ||||
1372 | { percolate => { | ||||
1373 | index => 'twitter', | ||||
1374 | type => 'tweet', | ||||
1375 | id => 1 | ||||
1376 | }}, | ||||
1377 | {}, | ||||
1378 | ] | ||||
1379 | ); | ||||
1380 | |||||
1381 | Query string parameters: | ||||
1382 | C<allow_no_indices>, | ||||
1383 | C<expand_wildcards>, | ||||
1384 | C<ignore_unavailable> | ||||
1385 | |||||
1386 | See the L<mpercolate docs|http://www.elastic.co/guide/en/elasticsearch/reference/current/search-percolate.html> | ||||
1387 | for more information. | ||||
1388 | |||||
1389 | =head2 C<suggest()> | ||||
1390 | |||||
1391 | $results = $e->suggest( | ||||
1392 | index => 'index' | \@indices, # optional | ||||
1393 | |||||
1394 | body => { suggest request } # required | ||||
1395 | ); | ||||
1396 | |||||
1397 | The C<suggest()> method is used to run | ||||
1398 | L<did-you-mean|http://www.elastic.co/guide/en/elasticsearch/reference/current/search-suggesteres-phrase.html> | ||||
1399 | or L<search-as-you-type|http://www.elastic.co/guide/en/elasticsearch/reference/current/search-suggesters-completion.html> | ||||
1400 | suggestion requests, which can also be run as part of a L</search()> request. | ||||
1401 | |||||
1402 | $results = $e->suggest( | ||||
1403 | index => 'my_index', | ||||
1404 | body => { | ||||
1405 | my_suggestions => { | ||||
1406 | phrase => { | ||||
1407 | text => 'johnny walker', | ||||
1408 | field => 'title' | ||||
1409 | } | ||||
1410 | } | ||||
1411 | } | ||||
1412 | ); | ||||
1413 | |||||
1414 | Query string parameters: | ||||
1415 | C<allow_no_indices>, | ||||
1416 | C<expand_wildcards>, | ||||
1417 | C<ignore_unavailable>, | ||||
1418 | C<preference>, | ||||
1419 | C<routing> | ||||
1420 | |||||
1421 | =head1 INDEXED SCRIPT METHODS | ||||
1422 | |||||
1423 | If dynamic scripting is enabled, Elasticsearch allows you to store scripts in an internal index known as | ||||
1424 | C<.scripts> and reference them by id. The methods to manage indexed scripts are as follows: | ||||
1425 | |||||
1426 | =head2 C<put_script()> | ||||
1427 | |||||
1428 | $result = $e->put_script( | ||||
1429 | lang => 'lang', # required | ||||
1430 | id => 'id', # required | ||||
1431 | body => { script } # required | ||||
1432 | ); | ||||
1433 | |||||
1434 | The C<put_script()> method is used to store a script in the C<.scripts> index. For instance: | ||||
1435 | |||||
1436 | $result = $e->put_scripts( | ||||
1437 | lang => 'groovy', | ||||
1438 | id => 'hello_world', | ||||
1439 | body => { | ||||
1440 | script => q(return "hello world"); | ||||
1441 | } | ||||
1442 | ); | ||||
1443 | |||||
1444 | Query string parameters: | ||||
1445 | C<op_type>, | ||||
1446 | C<version>, | ||||
1447 | C<version_type> | ||||
1448 | |||||
1449 | See the L<indexed scripts docs|http://www.elastic.co/guide/en/elasticsearch/reference/current/modules-scripting.html#_indexed_scripts> for more. | ||||
1450 | |||||
1451 | =head2 C<get_script()> | ||||
1452 | |||||
1453 | $script = $e->get_script( | ||||
1454 | lang => 'lang', # required | ||||
1455 | id => 'id', # required | ||||
1456 | ); | ||||
1457 | |||||
1458 | Retrieve the indexed script from the C<.scripts> index. | ||||
1459 | |||||
1460 | Query string parameters: | ||||
1461 | C<version>, | ||||
1462 | C<version_type> | ||||
1463 | |||||
1464 | See the L<indexed scripts docs|http://www.elastic.co/guide/en/elasticsearch/reference/current/modules-scripting.html#_indexed_scripts> for more. | ||||
1465 | |||||
1466 | =head2 C<delete_script()> | ||||
1467 | |||||
1468 | $script = $e->delete_script( | ||||
1469 | lang => 'lang', # required | ||||
1470 | id => 'id', # required | ||||
1471 | ); | ||||
1472 | |||||
1473 | Delete the indexed script from the C<.scripts> index. | ||||
1474 | |||||
1475 | Query string parameters: | ||||
1476 | C<version>, | ||||
1477 | C<version_type> | ||||
1478 | |||||
1479 | See the L<indexed scripts docs|http://www.elastic.co/guide/en/elasticsearch/reference/current/modules-scripting.html#_indexed_scripts> for more. | ||||
1480 | |||||
1481 | =head1 INDEXED SEARCH TEMPLATE METHODS | ||||
1482 | |||||
1483 | Mustache templates can be used to create search requests. These templates can | ||||
1484 | be stored in the C<.scripts> index and retrieved by ID. The methods to | ||||
1485 | manage indexed scripts are as follows: | ||||
1486 | |||||
1487 | =head2 C<put_template()> | ||||
1488 | |||||
1489 | $result = $e->put_template( | ||||
1490 | id => 'id', # required | ||||
1491 | body => { template } || "template" # required | ||||
1492 | ); | ||||
1493 | |||||
1494 | The C<put_template()> method is used to store a template in the C<.scripts> index. | ||||
1495 | For instance: | ||||
1496 | |||||
1497 | $result = $e->put_template( | ||||
1498 | id => 'hello_world', | ||||
1499 | body => { | ||||
1500 | template => { | ||||
1501 | query => { | ||||
1502 | match => { | ||||
1503 | title => "hello world" | ||||
1504 | } | ||||
1505 | } | ||||
1506 | } | ||||
1507 | } | ||||
1508 | ); | ||||
1509 | |||||
1510 | Query string parameters: None | ||||
1511 | |||||
1512 | See the L<indexed search template docs|http://www.elastic.co/guide/en/elasticsearch/reference/current/search-template.html#_pre_registered_template> for more. | ||||
1513 | |||||
1514 | =head2 C<get_template()> | ||||
1515 | |||||
1516 | $script = $e->get_template( | ||||
1517 | id => 'id', # required | ||||
1518 | ); | ||||
1519 | |||||
1520 | Retrieve the indexed template from the C<.scripts> index. | ||||
1521 | |||||
1522 | Query string parameters: | ||||
1523 | C<version>, | ||||
1524 | C<version_type> | ||||
1525 | |||||
1526 | See the L<indexed search template docs|http://www.elastic.co/guide/en/elasticsearch/reference/current/search-template.html#_pre_registered_template> for more. | ||||
1527 | |||||
1528 | =head2 C<delete_template()> | ||||
1529 | |||||
1530 | $script = $e->delete_template( | ||||
1531 | id => 'id', # required | ||||
1532 | ); | ||||
1533 | |||||
1534 | Delete the indexed template from the C<.scripts> index. | ||||
1535 | |||||
1536 | Query string parameters: None | ||||
1537 | |||||
1538 | See the L<indexed search template docs|http://www.elastic.co/guide/en/elasticsearch/reference/current/search-template.html#_pre_registered_template> for more. | ||||
1539 | |||||
1540 | =head1 AUTHOR | ||||
1541 | |||||
1542 | Clinton Gormley <drtech@cpan.org> | ||||
1543 | |||||
1544 | =head1 COPYRIGHT AND LICENSE | ||||
1545 | |||||
1546 | This software is Copyright (c) 2016 by Elasticsearch BV. | ||||
1547 | |||||
1548 | This is free software, licensed under: | ||||
1549 | |||||
1550 | The Apache License, Version 2.0, January 2004 | ||||
1551 | |||||
1552 | =cut | ||||
1553 | |||||
1554 | __END__ |