2_0/Direct.pm untested

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