Elasticsearch::Role::Cxn::HTTP - Provides common functionality to HTTP Cxn implementations
version 0.71
Elasticsearch::Role::Cxn::HTTP provides common functionality to the Cxn implementations which use the HTTP protocol. Cxn instances are created by a Elasticsearch::Role::CxnPool implentation, using the Elasticsearch::Cxn::Factory class.
This class does Elasticsearch::Role::Cxn.
The configuration options are as follows:
node
A single node is passed to new() by the Elasticsearch::Cxn::Factory class. It can either be a URI or a hash containing each part. For instance:
new()
node => 'localhost'; # equiv of 'http://localhost:80' node => 'localhost:9200'; # equiv of 'http://localhost:9200' node => 'http://localhost:9200'; node => 'https://localhost'; # equiv of 'https://localhost:443' node => 'localhost/path'; # equiv of 'http://localhost:80/path' node => 'http://user:pass@localhost'; # equiv of 'http://localhost:80' # with userinfo => 'user:pass'
Alternatively, a node can be specified as a hash:
{ scheme => 'http', host => 'search.domain.com', port => '9200', path => '/path', userinfo => 'user:pass' }
Similarly, default values can be specified with port, path_prefix, userinfo and https:
port
path_prefix
userinfo
https
$e = Elasticsearch->new( port => 9201, path_prefix => '/path', userinfo => 'user:pass', https => 1, nodes => [ 'search1', 'search2' ] )
max_content_length
By default, Elasticsearch nodes accept a maximum post body of 100MB or 104_857_600 bytes. This client enforces that limit. The limit can be customised with the max_content_length parameter (specified in bytes).
104_857_600
If you're using the Elasticsearch::CxnPool::Sniff module, then the max_content_length will be automatically retrieved from the live cluster, unless you specify a custom max_content_length:
# max_content_length retrieved from cluster $e = Elasticsearch->new( cxn_pool => 'Sniff' ); # max_content_length fixed at 10,000 bytes $e = Elasticsearch->new( cxn_pool => 'Sniff', max_content_length => 10_000 );
deflate
This client can request compressed responses from Elasticsearch by enabling the http.compression config setting in Elasticsearch and setting deflate to true:
http.compression
true
$e = Elasticsearch->new( deflate => 1 );
None of the methods listed below are useful to the user. They are documented for those who are writing alternative implementations only.
scheme()
$scheme = $cxn->scheme;
Returns the scheme of the connection, ie http or https.
http
is_https()
$bool = $cxn->is_https;
Returns true or false depending on whether the /scheme() is https or not.
false
/scheme()
userinfo()
$userinfo = $cxn->userinfo
Returns the username and password of the cxn, if any, eg "user:pass". If userinfo is provided, then a Basic Authorization header is added to each request.
"user:pass"
default_headers()
$headers = $cxn->default_headers
The default headers that are passed with each request. This includes the Accept-Encoding header if /deflate is true, and the Authorization header if /userinfo has a value.
Accept-Encoding
/deflate
Authorization
/userinfo
max_content_length()
$int = $cxn->max_content_length;
Returns the maximum length in bytes that the HTTP body can have.
build_uri()
$uri = $cxn->build_uri({ path => '/_search', qs => { size => 10 }});
Returns the HTTP URI to use for a particular request, combining the passed in path parameter with any defined path_prefix, and adding the query-string parameters.
path
Clinton Gormley <drtech@cpan.org>
This software is Copyright (c) 2013 by Elasticsearch BV.
This is free software, licensed under:
The Apache License, Version 2.0, January 2004
To install Elasticsearch, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Elasticsearch
CPAN shell
perl -MCPAN -e shell install Elasticsearch
For more information on module installation, please visit the detailed CPAN module installation guide.