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