6_0/Direct.pm untested

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