NAME

App::ElasticSearch::Utilities::Connection - Abstract the connection element

VERSION

version 7.6

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 es_request method maintains compatability with older versions and emulates the API you'd expect from Elastijk.

ATTRIBUTES

host

Hostname or ip to connect to, default 'localhost'

port

Port to connect the HTTP transport for the ElasticSearch cluster, default is 9200

proto

Protocol to use, defaults to 'http'.

This module converts from the performance concerned backend of Hijk and Elastijk, to the feature rich LWP::UserAgent. This means we can now support TLS communication to the ES back-end and things like basic authentication.

timeout

Connection and Read Timeout for the HTTP connection, defaults to 10 seconds.

ua

Lazy built LWP::UserAgent to access LWP::UserAgent directly.

METHODS

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 HTTP::Response object from LWP::UserAgent instead of the more simplistic return values of Hijk and Elastijk. Use App::ElasticSearch::Utilities::es_request for a simpler interface.

exists( index => 'name' )

Takes the name of an index, returns true if the index exists, false otherwise.

put( body => ... , index => ... )

Parameter 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.

bulk( body => ..., index => ... )

Parameter body is required. The body should be an array containing the command and documents to send to the ElasticSearch bulk API, see: Bulk API

Returns a list containing the HTTP Status Code, and the Response Content.

AUTHOR

Brad Lhotsky <brad@divisionbyzero.net>

COPYRIGHT AND LICENSE

This software is Copyright (c) 2020 by Brad Lhotsky.

This is free software, licensed under:

The (three-clause) BSD License