.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Search::Elasticsearch 3pm" .TH Search::Elasticsearch 3pm 2024-02-04 "perl v5.38.2" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH NAME Search::Elasticsearch \- The official client for Elasticsearch .SH VERSION .IX Header "VERSION" version 8.12 .SH SYNOPSIS .IX Header "SYNOPSIS" .Vb 1 \& use Search::Elasticsearch; \& \& # Connect to localhost:9200: \& \& my $e = Search::Elasticsearch\->new(); \& \& # Round\-robin between two nodes: \& \& my $e = Search::Elasticsearch\->new( \& nodes => [ \& \*(Aqsearch1:9200\*(Aq, \& \*(Aqsearch2:9200\*(Aq \& ] \& ); \& \& # Connect to cluster at search1:9200, sniff all nodes and round\-robin between them: \& \& my $e = Search::Elasticsearch\->new( \& nodes => \*(Aqsearch1:9200\*(Aq, \& cxn_pool => \*(AqSniff\*(Aq \& ); \& \& # Index a document: \& \& $e\->index( \& index => \*(Aqmy_app\*(Aq, \& type => \*(Aqblog_post\*(Aq, \& id => 1, \& body => { \& title => \*(AqElasticsearch clients\*(Aq, \& content => \*(AqInteresting content...\*(Aq, \& date => \*(Aq2013\-09\-24\*(Aq \& } \& ); \& \& # Get the document: \& \& my $doc = $e\->get( \& index => \*(Aqmy_app\*(Aq, \& type => \*(Aqblog_post\*(Aq, \& id => 1 \& ); \& \& # Search: \& \& my $results = $e\->search( \& index => \*(Aqmy_app\*(Aq, \& body => { \& query => { \& match => { title => \*(Aqelasticsearch\*(Aq } \& } \& } \& ); \& \& # Cluster requests: \& \& $info = $e\->cluster\->info; \& $health = $e\->cluster\->health; \& $node_stats = $e\->cluster\->node_stats; \& \& # Index requests: \& \& $e\->indices\->create(index=>\*(Aqmy_index\*(Aq); \& $e\->indices\->delete(index=>\*(Aqmy_index\*(Aq); .Ve .SH DESCRIPTION .IX Header "DESCRIPTION" Search::Elasticsearch is the official Perl client for Elasticsearch, supported by elastic.co . 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 elastic.co . .SH "PREVIOUS VERSIONS OF ELASTICSEARCH" .IX Header "PREVIOUS VERSIONS OF ELASTICSEARCH" This version of the client supports the Elasticsearch 7.0 branch, which is not backwards compatible with earlier branches. .PP If you need to talk to a version of Elasticsearch before 7.0.0, please install one of the following packages: .IP \(bu 4 Search::Elasticsearch::Client::6_0 .IP \(bu 4 Search::Elasticsearch::Client::5_0 .IP \(bu 4 Search::Elasticsearch::Client::2_0 .IP \(bu 4 Search::Elasticsearch::Client::1_0 .IP \(bu 4 Search::Elasticsearch::Client::0_90 .SS Motivation .IX Subsection "Motivation" .RS 4 \&\fIThe greatest deception men suffer is from their own opinions.\fR .Sp Leonardo da Vinci .RE .PP 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 Elasticsearch reference documentation and understand how to use this client, or any of the other official clients. .PP 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. .SS Features .IX Subsection "Features" This client provides: .IP \(bu 4 Full support for all Elasticsearch APIs .IP \(bu 4 HTTP backend (for an async backend using Promises, see Search::Elasticsearch::Async) .IP \(bu 4 Robust networking support which handles load balancing, failure detection and failover .IP \(bu 4 Good defaults .IP \(bu 4 Helper utilities for more complex operations, such as bulk indexing, and scrolled searches .IP \(bu 4 Logging support via Log::Any .IP \(bu 4 Compatibility with the official clients for Python, Ruby, PHP, and Javascript .IP \(bu 4 Easy extensibility .SH "INSTALLING ELASTICSEARCH" .IX Header "INSTALLING ELASTICSEARCH" You can download the latest version of Elasticsearch from . See the installation instructions for details. You will need to have a recent version of Java installed, preferably the Java v8 from Sun. .SH "CREATING A NEW INSTANCE" .IX Header "CREATING A NEW INSTANCE" The "\fBnew()\fR" method returns a new client which can be used to run requests against the Elasticsearch cluster. .PP .Vb 2 \& use Search::Elasticsearch; \& my $e = Search::Elasticsearch\->new( %params ); .Ve .PP The most important arguments to "\fBnew()\fR" are the following: .ie n .SS """nodes""" .el .SS \f(CWnodes\fP .IX Subsection "nodes" The \f(CW\*(C`nodes\*(C'\fR 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 \f(CW\*(C`localhost:9200\*(C'\fR: .PP .Vb 2 \& # default: localhost:9200 \& $e = Search::Elasticsearch\->new(); \& \& # single \& $e = Search::Elasticsearch\->new( nodes => \*(Aqsearch_1:9200\*(Aq); \& \& # multiple \& $e = Search::Elasticsearch\->new( \& nodes => [ \& \*(Aqsearch_1:9200\*(Aq, \& \*(Aqsearch_2:9200\*(Aq \& ] \& ); .Ve .PP Each \f(CW\*(C`node\*(C'\fR can be a URL including a scheme, host, port, path and userinfo (for authentication). For instance, this would be a valid node: .PP .Vb 1 \& https://username:password@search.domain.com:443/prefix/path .Ve .PP See "node" in Search::Elasticsearch::Role::Cxn for more on node specification. .ie n .SS """cxn_pool""" .el .SS \f(CWcxn_pool\fP .IX Subsection "cxn_pool" The CxnPool modules manage connections to nodes in the Elasticsearch cluster. They handle the load balancing between nodes and failover when nodes fail. Which \f(CW\*(C`CxnPool\*(C'\fR you should use depends on where your cluster is. There are three choices: .IP \(bu 4 \&\f(CW\*(C`Static\*(C'\fR .Sp .Vb 7 \& $e = Search::Elasticsearch\->new( \& cxn_pool => \*(AqStatic\*(Aq # default \& nodes => [ \& \*(Aqsearch1.domain.com:9200\*(Aq, \& \*(Aqsearch2.domain.com:9200\*(Aq \& ], \& ); .Ve .Sp The 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 Search::Elasticsearch::CxnPool::Static for more. .IP \(bu 4 \&\f(CW\*(C`Sniff\*(C'\fR .Sp .Vb 7 \& $e = Search::Elasticsearch\->new( \& cxn_pool => \*(AqSniff\*(Aq, \& nodes => [ \& \*(Aqsearch1:9200\*(Aq, \& \*(Aqsearch2:9200\*(Aq \& ], \& ); .Ve .Sp The Sniff connection pool should be used when you \fBdo\fR 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 \fIdiscover\fR the cluster, which is then \fIsniffed\fR to find the current list of live nodes that the cluster knows about. See Search::Elasticsearch::CxnPool::Sniff. .IP \(bu 4 \&\f(CW\*(C`Static::NoPing\*(C'\fR .Sp .Vb 7 \& $e = Search::Elasticsearch\->new( \& cxn_pool => \*(AqStatic::NoPing\*(Aq \& nodes => [ \& \*(Aqproxy1.domain.com:80\*(Aq, \& \*(Aqproxy2.domain.com:80\*(Aq \& ], \& ); .Ve .Sp The 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 \f(CW\*(C`HEAD /\*(C'\fR request. .Sp See Search::Elasticsearch::CxnPool::Static::NoPing for more. .ie n .SS """trace_to""" .el .SS \f(CWtrace_to\fP .IX Subsection "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 \f(CW\*(C`trace_to\*(C'\fR parameter, as follows: .PP .Vb 4 \& # To STDERR \& $e = Search::Elasticsearch\->new( \& trace_to => \*(AqStderr\*(Aq \& ); \& \& # To a file \& $e = Search::Elasticsearch\->new( \& trace_to => [\*(AqFile\*(Aq,\*(Aq/path/to/filename\*(Aq] \& ); .Ve .PP Logging is handled by Log::Any. See Search::Elasticsearch::Logger::LogAny for more information. .SS Other .IX Subsection "Other" Other arguments are explained in the respective module docs. .SH "RUNNING REQUESTS" .IX Header "RUNNING REQUESTS" When you create a new instance of Search::Elasticsearch, it returns a client object, which can be used for running requests. .PP .Vb 2 \& use Search::Elasticsearch; \& my $e = Search::Elasticsearch\->new( %params ); \& \& # create an index \& $e\->indices\->create( index => \*(Aqmy_index\*(Aq ); \& \& # index a document \& $e\->index( \& index => \*(Aqmy_index\*(Aq, \& type => \*(Aqblog_post\*(Aq, \& id => 1, \& body => { \& title => \*(AqElasticsearch clients\*(Aq, \& content => \*(AqInteresting content...\*(Aq, \& date => \*(Aq2013\-09\-24\*(Aq \& } \& ); .Ve .PP See Search::Elasticsearch::Client::6_0::Direct for more details about the requests that can be run. .SH MODULES .IX Header "MODULES" Each chunk of functionality is handled by a different module, which can be specified in the call to \fBnew()\fR as shown in cxn_pool above. For instance, the following will use the Search::Elasticsearch::CxnPool::Sniff module for the connection pool. .PP .Vb 3 \& $e = Search::Elasticsearch\->new( \& cxn_pool => \*(AqSniff\*(Aq \& ); .Ve .PP Custom modules can be named with the appropriate prefix, eg \f(CW\*(C`Search::Elasticsearch::CxnPool::\*(C'\fR, or by prefixing the full class name with \f(CW\*(C`+\*(C'\fR: .PP .Vb 3 \& $e = Search::Elasticsearch\->new( \& cxn_pool => \*(Aq+My::Custom::CxnClass\*(Aq \& ); .Ve .PP The modules that you can override are specified with the following arguments to "\fBnew()\fR": .ie n .SS """client""" .el .SS \f(CWclient\fP .IX Subsection "client" The class to use for the client functionality, which provides methods that can be called to execute requests, such as \&\f(CWsearch()\fR, \f(CWindex()\fR or \f(CWdelete()\fR. The client parses the user's requests and passes them to the "transport" class to be executed. .PP The default version of the client is \f(CW\*(C`7_0::Direct\*(C'\fR, which can be explicitly specified as follows: .PP .Vb 3 \& $e = Search::Elasticsearch\->new( \& client => \*(Aq7_0::Direct\*(Aq \& ); .Ve .ie n .SS """transport""" .el .SS \f(CWtransport\fP .IX Subsection "transport" The Transport class accepts a parsed request from the "client" class, fetches a "cxn" from its "cxn_pool" and tries to execute the request, retrying after failure where appropriate. See: .IP \(bu 4 Search::Elasticsearch::Transport .ie n .SS """cxn""" .el .SS \f(CWcxn\fP .IX Subsection "cxn" The class which handles raw requests to Elasticsearch nodes. See: .IP \(bu 4 Search::Elasticsearch::Cxn::HTTPTiny (default) .IP \(bu 4 Search::Elasticsearch::Cxn::LWP .IP \(bu 4 Search::Elasticsearch::Cxn::NetCurl .ie n .SS """cxn_factory""" .el .SS \f(CWcxn_factory\fP .IX Subsection "cxn_factory" The class which the "cxn_pool" uses to create new "cxn" objects. See: .IP \(bu 4 Search::Elasticsearch::Cxn::Factory .ie n .SS """cxn_pool"" (2)" .el .SS "\f(CWcxn_pool\fP (2)" .IX Subsection "cxn_pool (2)" The class to use for the connection pool functionality. It calls the "cxn_factory" class to create new "cxn" objects when appropriate. See: .IP \(bu 4 Search::Elasticsearch::CxnPool::Static (default) .IP \(bu 4 Search::Elasticsearch::CxnPool::Sniff .IP \(bu 4 Search::Elasticsearch::CxnPool::Static::NoPing .ie n .SS """logger""" .el .SS \f(CWlogger\fP .IX Subsection "logger" The class to use for logging events and tracing HTTP requests/responses. See: .IP \(bu 4 Search::Elasticsearch::Logger::LogAny .ie n .SS """serializer""" .el .SS \f(CWserializer\fP .IX Subsection "serializer" The class to use for serializing request bodies and deserializing response bodies. See: .IP \(bu 4 Search::Elasticsearch::Serializer::JSON (default) .IP \(bu 4 Search::Elasticsearch::Serializer::JSON::Cpanel .IP \(bu 4 Search::Elasticsearch::Serializer::JSON::XS .IP \(bu 4 Search::Elasticsearch::Serializer::JSON::PP .SH BUGS .IX Header "BUGS" This is a stable API but this implementation is new. Watch this space for new releases. .PP If you have any suggestions for improvements, or find any bugs, please report them to . I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. .SH SUPPORT .IX Header "SUPPORT" You can find documentation for this module with the perldoc command. .PP .Vb 1 \& perldoc Search::Elasticsearch .Ve .PP You can also look for information at: .IP \(bu 4 GitHub .Sp .IP \(bu 4 CPAN Ratings .Sp .IP \(bu 4 Search MetaCPAN .Sp .IP \(bu 4 IRC .Sp The #elasticsearch channel on \&\f(CW\*(C`irc.freenode.net\*(C'\fR. .IP \(bu 4 Mailing list .Sp The main Elasticsearch mailing list . .SH "TEST SUITE" .IX Header "TEST SUITE" The full test suite requires a live Elasticsearch node to run, and should be run as : .PP .Vb 2 \& perl Makefile.PL \& ES=localhost:9200 make test .Ve .PP \&\fBTESTS RUN IN THIS WAY ARE DESTRUCTIVE! DO NOT RUN AGAINST A CLUSTER WITH DATA YOU WANT TO KEEP!\fR .PP You can change the Cxn class which is used by setting the \f(CW\*(C`ES_CXN\*(C'\fR environment variable: .PP .Vb 1 \& ES_CXN=NetCurl ES=localhost:9200 make test .Ve .SH AUTHOR .IX Header "AUTHOR" Enrico Zimuel .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" This software is Copyright (c) 2024 by Elasticsearch BV. .PP This is free software, licensed under: .PP .Vb 1 \& The Apache License, Version 2.0, January 2004 .Ve