App-ElasticSearch-Utilities
view release on metacpan or search on metacpan
lib/App/ElasticSearch/Utilities/Connection.pm view on Meta::CPAN
__PACKAGE__->meta->make_immutable;
__END__
=pod
=head1 NAME
App::ElasticSearch::Utilities::Connection - Abstract the connection element
=head1 VERSION
version 8.8
=head1 SYNOPSIS
For most users, this code will never be called directly since this module
doesn't handle parameter parsing on the CLI. To get an object, instead call:
use App::ElasticSearch::Utilities qw(es_connect);
my $es = es_connect();
my $http_response_obj = $es->request('_search',
{
index=>'logstash',
uri_param => {
size => 10,
}
},
{
query => {
query_string => "program:sshd",
}
}
);
Though even this is overkill. The B<es_request> method maintains compatability with older versions and emulates
the API you'd expect from B<Elastijk>.
=head1 ATTRIBUTES
=head2 host
Hostname or ip to connect to, default 'B<localhost>'
=head2 port
Port to connect the HTTP transport for the ElasticSearch cluster, default is B<9200>
=head2 proto
Protocol to use, defaults to 'B<http>'.
This module converts from the performance concerned backend of B<Hijk> and B<Elastijk>, to the feature
rich B<LWP::UserAgent>. This means we can now support TLS communication to the ES back-end and things like
basic authentication.
=head2 timeout
Connection and Read Timeout for the HTTP connection, defaults to B<10> seconds.
=head2 username
HTTP Basic Authorization username, defaults to C<$ENV{USER}>.
=head2 password
HTTP Basic Authorization password, if set, we'll try authentication.
=head2 ssl_opts
SSL Options for L<LWP::UserAgent/ssl_opts>.
=head2 ua
Lazy built B<LWP::UserAgent> to access LWP::UserAgent directly.
=head1 METHODS
=head2 request( $command, { index => ... uri_param => { size => 1 } }, $body )
This method provides a wrapper between the Hijk/Elastijk request syntax and the
LWP::UserAgent flow. It's return value is the B<HTTP::Response> object from
B<LWP::UserAgent> instead of the more simplistic return values of B<Hijk> and
B<Elastijk>. Use B<App::ElasticSearch::Utilities::es_request> for a simpler
interface.
=head2 exists( index => 'name' )
Takes the name of an index, returns true if the index exists, false otherwise.
=head2 put( body => ... , index => ... )
Parameter B<body> is required. Puts something to an index. This is often used to
put settings and/or mappings to an index.
Returns a list containing the HTTP Status Code, and the Response Content.
=head2 bulk( body => ..., index => ... )
Parameter B<body> is required. The body should be an array containing the command and documents to send to the
ElasticSearch bulk API, see: L<Bulk API|https://www.elastic.co/guide/en/elasticsearch/reference/2.3/docs-bulk.html>
Returns a list containing the HTTP Status Code, and the Response Content.
=head1 AUTHOR
Brad Lhotsky <brad@divisionbyzero.net>
=head1 COPYRIGHT AND LICENSE
This software is Copyright (c) 2024 by Brad Lhotsky.
This is free software, licensed under:
The (three-clause) BSD License
=cut
( run in 0.689 second using v1.01-cache-2.11-cpan-39bf76dae61 )