/usr/share/perl5/Search/Elasticsearch.pm is in libsearch-elasticsearch-perl 5.01-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 | package Search::Elasticsearch;
use Moo 1.003 ();
use Search::Elasticsearch::Util qw(parse_params load_plugin);
use namespace::clean;
our $VERSION = '5.01';
my %Default_Plugins = (
client => [ 'Search::Elasticsearch::Client', '5_0::Direct' ],
cxn_factory => [ 'Search::Elasticsearch::Cxn::Factory', '' ],
cxn_pool => [ 'Search::Elasticsearch::CxnPool', 'Static' ],
logger => [ 'Search::Elasticsearch::Logger', 'LogAny' ],
serializer => [ 'Search::Elasticsearch::Serializer', 'JSON' ],
transport => [ 'Search::Elasticsearch::Transport', '' ],
);
my @Load_Order = qw(
serializer
logger
cxn_factory
cxn_pool
transport
client
);
#===================================
sub new {
#===================================
my ( $class, $params ) = parse_params(@_);
$params->{cxn} ||= 'HTTPTiny';
my $plugins = delete $params->{plugins} || [];
$plugins = [$plugins] unless ref $plugins eq 'ARRAY';
for my $name (@Load_Order) {
my ( $base, $default ) = @{ $Default_Plugins{$name} };
my $sub_class = $params->{$name} || $default;
my $plugin_class = load_plugin( $base, $sub_class );
$params->{$name} = $plugin_class->new($params);
}
for my $name (@$plugins) {
my $plugin_class
= load_plugin( 'Search::Elasticsearch::Plugin', $name );
$plugin_class->_init_plugin($params);
}
return $params->{client};
}
1;
=pod
=encoding UTF-8
=head1 NAME
Search::Elasticsearch - The official client for Elasticsearch
=head1 VERSION
version 5.01
=head1 SYNOPSIS
use Search::Elasticsearch;
# Connect to localhost:9200:
my $e = Search::Elasticsearch->new();
# Round-robin between two nodes:
my $e = Search::Elasticsearch->new(
nodes => [
'search1:9200',
'search2:9200'
]
);
# Connect to cluster at search1:9200, sniff all nodes and round-robin between them:
my $e = Search::Elasticsearch->new(
nodes => 'search1:9200',
cxn_pool => 'Sniff'
);
# Index a document:
$e->index(
index => 'my_app',
type => 'blog_post',
id => 1,
body => {
title => 'Elasticsearch clients',
content => 'Interesting content...',
date => '2013-09-24'
}
);
# Get the document:
my $doc = $e->get(
index => 'my_app',
type => 'blog_post',
id => 1
);
# Search:
my $results = $e->search(
index => 'my_app',
body => {
query => {
match => { title => 'elasticsearch' }
}
}
);
# Cluster requests:
$info = $e->cluster->info;
$health = $e->cluster->health;
$node_stats = $e->cluster->node_stats;
# Index requests:
$e->indices->create(index=>'my_index');
$e->indices->delete(index=>'my_index');
=head1 DESCRIPTION
L<Search::Elasticsearch> is the official Perl client for Elasticsearch,
supported by L<elasticsearch.com|http://www.elasticsearch.com>. Elasticsearch
itself is a flexible and powerful open source, distributed real-time
search and analytics engine for the cloud. You can read more about it
on L<elastic.co|http://www.elastic.co>.
=head1 PREVIOUS VERSIONS OF ELASTICSEARCH
This version of the client supports the Elasticsearch 5.0 branch,
which is not backwards compatible with earlier branches.
If you need to talk to a version of Elasticsearch before 5.0.0, please
install one of the following packages:
=over
=item *
L<Search::Elasticsearch::Client::2_0>
=item *
L<Search::Elasticsearch::Client::1_0>
=item *
L<Search::Elasticsearch::Client::0_90>
=back
=head2 Motivation
=over
I<The greatest deception men suffer is from their own opinions.>
Leonardo da Vinci
=back
All of us have opinions, especially when it comes to designing APIs.
Unfortunately, the opinions of programmers seldom coincide. The intention of
this client, and of the officially supported clients available for other
languages, is to provide robust support for the full native Elasticsearch API
with as few opinions as possible: you should be able to read the
L<Elasticsearch reference documentation|http://www.elastic.co/guide>
and understand how to use this client, or any of the other official clients.
Should you decide that you want to customize the API, then this client
provides the basis for your code. It does the hard stuff for you,
allowing you to build on top of it.
=head2 Features
This client provides:
=over
=item *
Full support for all Elasticsearch APIs
=item *
HTTP backend (for an async backend using L<Promises>, see
L<Search::Elasticsearch::Async>)
=item *
Robust networking support which handles load balancing, failure detection
and failover
=item *
Good defaults
=item *
Helper utilities for more complex operations, such as
L<bulk indexing|Search::Elasticsearch::Client::5_0::Bulk>, and
L<scrolled searches|Search::Elasticsearch::Client::5_0::Scroll>
=item *
Logging support via L<Log::Any>
=item *
Compatibility with the official clients for Python, Ruby, PHP, and Javascript
=item *
Easy extensibility
=back
=head1 INSTALLING ELASTICSEARCH
You can download the latest version of Elasticsearch from
L<http://www.elastic.co/download>. See the
L<installation instructions|https://www.elastic.co/guide/en/elasticsearch/reference/current/setup.html>
for details. You will need to have a recent version of Java installed,
preferably the Java v8 from Sun.
=head1 CREATING A NEW INSTANCE
The L</new()> method returns a new L<client|Search::Elasticsearch::Client::5_0::Direct>
which can be used to run requests against the Elasticsearch cluster.
use Search::Elasticsearch;
my $e = Search::Elasticsearch->new( %params );
The most important arguments to L</new()> are the following:
=head2 C<nodes>
The C<nodes> parameter tells the client which Elasticsearch nodes it should
talk to. It can be a single node, multiples nodes or, if not
specified, will default to C<localhost:9200>:
# default: localhost:9200
$e = Search::Elasticsearch->new();
# single
$e = Search::Elasticsearch->new( nodes => 'search_1:9200');
# multiple
$e = Search::Elasticsearch->new(
nodes => [
'search_1:9200',
'search_2:9200'
]
);
Each C<node> can be a URL including a scheme, host, port, path and userinfo
(for authentication). For instance, this would be a valid node:
https://username:password@search.domain.com:443/prefix/path
See L<Search::Elasticsearch::Role::Cxn/node> for more on node specification.
=head2 C<cxn_pool>
The L<CxnPool|Search::Elasticsearch::Role::CxnPool> modules manage connections to
nodes in the Elasticsearch cluster. They handle the load balancing between
nodes and failover when nodes fail. Which C<CxnPool> you should use depends on
where your cluster is. There are three choices:
=over
=item * C<Static>
$e = Search::Elasticsearch->new(
cxn_pool => 'Static' # default
nodes => [
'search1.domain.com:9200',
'search2.domain.com:9200'
],
);
The L<Static|Search::Elasticsearch::CxnPool::Static> connection pool, which is the
default, should be used when you don't have direct access to the Elasticsearch
cluster, eg when you are accessing the cluster through a proxy. See
L<Search::Elasticsearch::CxnPool::Static> for more.
=item * C<Sniff>
$e = Search::Elasticsearch->new(
cxn_pool => 'Sniff',
nodes => [
'search1:9200',
'search2:9200'
],
);
The L<Sniff|Search::Elasticsearch::CxnPool::Sniff> connection pool should be used
when you B<do> have direct access to the Elasticsearch cluster, eg when
your web servers and Elasticsearch servers are on the same network.
The nodes that you specify are used to I<discover> the cluster, which is
then I<sniffed> to find the current list of live nodes that the cluster
knows about. See L<Search::Elasticsearch::CxnPool::Sniff>.
=item * C<Static::NoPing>
$e = Search::Elasticsearch->new(
cxn_pool => 'Static::NoPing'
nodes => [
'proxy1.domain.com:80',
'proxy2.domain.com:80'
],
);
The L<Static::NoPing|Search::Elasticsearch::CxnPool::Static::NoPing> connection
pool should be used when your access to a remote cluster is so limited
that you cannot ping individual nodes with a C<HEAD /> request.
See L<Search::Elasticsearch::CxnPool::Static::NoPing> for more.
=back
=head2 C<trace_to>
For debugging purposes, it is useful to be able to dump the actual HTTP
requests which are sent to the cluster, and the response that is received.
This can be enabled with the C<trace_to> parameter, as follows:
# To STDERR
$e = Search::Elasticsearch->new(
trace_to => 'Stderr'
);
# To a file
$e = Search::Elasticsearch->new(
trace_to => ['File','/path/to/filename']
);
Logging is handled by L<Log::Any>. See L<Search::Elasticsearch::Logger::LogAny>
for more information.
=head2 Other
Other arguments are explained in the respective L<module docs|/MODULES>.
=head1 RUNNING REQUESTS
When you create a new instance of Search::Elasticsearch, it returns a
L<client|Search::Elasticsearch::Client::5_0::Direct> object, which can be used for
running requests.
use Search::Elasticsearch;
my $e = Search::Elasticsearch->new( %params );
# create an index
$e->indices->create( index => 'my_index' );
# index a document
$e->index(
index => 'my_index',
type => 'blog_post',
id => 1,
body => {
title => 'Elasticsearch clients',
content => 'Interesting content...',
date => '2013-09-24'
}
);
See L<Search::Elasticsearch::Client::5_0::Direct> for more details about the requests that
can be run.
=head1 MODULES
Each chunk of functionality is handled by a different module,
which can be specified in the call to L<new()> as shown in L<cxn_pool> above.
For instance, the following will use the L<Search::Elasticsearch::CxnPool::Sniff>
module for the connection pool.
$e = Search::Elasticsearch->new(
cxn_pool => 'Sniff'
);
Custom modules can be named with the appropriate prefix,
eg C<Search::Elasticsearch::CxnPool::>, or by prefixing the full class name
with C<+>:
$e = Search::Elasticsearch->new(
cxn_pool => '+My::Custom::CxnClass'
);
The modules that you can override are specified with the following
arguments to L</new()>:
=head2 C<client>
The class to use for the client functionality, which provides
methods that can be called to execute requests, such as
C<search()>, C<index()> or C<delete()>. The client parses the user's
requests and passes them to the L</transport> class to be executed.
The default version of the client is C<5_0::Direct>, which can
be explicitly specified as follows:
$e = Search::Elasticsearch->new(
client => '5_0::Direct'
);
=head2 C<transport>
The Transport class accepts a parsed request from the L</client> class,
fetches a L</cxn> from its L</cxn_pool> and tries to execute the request,
retrying after failure where appropriate. See:
=over
=item * L<Search::Elasticsearch::Transport>
=back
=head2 C<cxn>
The class which handles raw requests to Elasticsearch nodes.
See:
=over
=item * L<Search::Elasticsearch::Cxn::HTTPTiny> (default)
=item * L<Search::Elasticsearch::Cxn::Hijk>
=item * L<Search::Elasticsearch::Cxn::LWP>
=item * L<Search::Elasticsearch::Cxn::NetCurl>
=back
=head2 C<cxn_factory>
The class which the L</cxn_pool> uses to create new L</cxn> objects.
See:
=over
=item * L<Search::Elasticsearch::Cxn::Factory>
=back
=head2 C<cxn_pool> (2)
The class to use for the L<connection pool|/cxn_pool> functionality.
It calls the L</cxn_factory> class to create new L</cxn> objects when
appropriate. See:
=over
=item * L<Search::Elasticsearch::CxnPool::Static> (default)
=item * L<Search::Elasticsearch::CxnPool::Sniff>
=item * L<Search::Elasticsearch::CxnPool::Static::NoPing>
=back
=head2 C<logger>
The class to use for logging events and tracing HTTP requests/responses. See:
=over
=item * L<Search::Elasticsearch::Logger::LogAny>
=back
=head2 C<serializer>
The class to use for serializing request bodies and deserializing response
bodies. See:
=over
=item * L<Search::Elasticsearch::Serializer::JSON> (default)
=item * L<Search::Elasticsearch::Serializer::JSON::Cpanel>
=item * L<Search::Elasticsearch::Serializer::JSON::XS>
=item * L<Search::Elasticsearch::Serializer::JSON::PP>
=back
=head1 BUGS
This is a stable API but this implementation is new. Watch this space
for new releases.
If you have any suggestions for improvements, or find any bugs, please report
them to L<http://github.com/elasticsearch/elasticsearch-perl/issues>.
I will be notified, and then you'll automatically be notified of progress on
your bug as I make changes.
=head1 SUPPORT
You can find documentation for this module with the perldoc command.
perldoc Search::Elasticsearch
You can also look for information at:
=over 4
=item * GitHub
L<http://github.com/elasticsearch/elasticsearch-perl>
=item * CPAN Ratings
L<http://cpanratings.perl.org/d/Search::Elasticsearch>
=item * Search MetaCPAN
L<https://metacpan.org/module/Search::Elasticsearch>
=item * IRC
The L<#elasticsearch|irc://irc.freenode.net/elasticsearch> channel on
C<irc.freenode.net>.
=item * Mailing list
The main L<Elasticsearch mailing list|http://discuss.elastic.co>.
=back
=head1 TEST SUITE
The full test suite requires a live Elasticsearch node to run, and should
be run as :
perl Makefile.PL
ES=localhost:9200 make test
B<TESTS RUN IN THIS WAY ARE DESTRUCTIVE! DO NOT RUN AGAINST A CLUSTER WITH
DATA YOU WANT TO KEEP!>
You can change the Cxn class which is used by setting the C<ES_CXN>
environment variable:
ES_CXN=Hijk ES=localhost:9200 make test
=head1 AUTHOR
Clinton Gormley <drtech@cpan.org>
=head1 COPYRIGHT AND LICENSE
This software is Copyright (c) 2016 by Elasticsearch BV.
This is free software, licensed under:
The Apache License, Version 2.0, January 2004
=cut
__END__
# ABSTRACT: The official client for Elasticsearch
|