Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

An async libcurl backend for ElasticSearch.pm

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 build_scripts
Octocat-spinner-32 lib
Octocat-spinner-32 t
Octocat-spinner-32 .gitignore
Octocat-spinner-32 Changes
Octocat-spinner-32 README.pod
Octocat-spinner-32 dist.ini
README.pod

DESCRIPTION

ElasticSearch::Transport::AECurl uses AnyEvent::Multi::Curl (and thus libcurl) to talk to ElasticSearch asynchronously over HTTP.

SYNOPSIS

    use ElasticSearch;
    my $e = ElasticSearch->new(
        servers         => 'search.foo.com:9200',
        transport       => 'aecurl',

        timeout         => 30,
        max_concurrency => 0,
        proxy           => 'foo.bar.com',
        ip_resolve      => 4|6|undef,
    );

    # blocking request
    $e->cluster_health->recv;

    # non-blocking request
    $e->cluster_health->cb( sub {
        if ($@) {
            log "An error occurred: $@";
        } else {
            my $response = shift;
            log $response;
        }
    });
    AE::cv->recv();

    # fire-and-forget vs scoped
    {
        $e->delete_index(index => 'foo');
        $e->delete_index(index => 'bar')->cb( sub { print "Done"});
        my $cv = $e->delete_index(index=>'baz');
    }
    AE::cv->recv;
    #   - foo and bar will be deleted
    #   - baz will not be deleted

USING AECurl

Any request to ElasticSearch returns an AnyEvent::CondVar. You have three options for how you use them:

Blocking

    $cv = $e->cluster_health;
    $result = $cv->recv;

When you call recv() on a CondVar, your program will block until that CondVar is ready to return a value.

If an error was thrown, then recv() will die. You will need to wrap recv() in eval if you don't want to die.

If your $cv goes out of scope, then the request will be aborted.

Callback

    $e->cluster_health->cb( sub {
        if ($@) {
            log "Error $@";
        }
        else {
            my $result = shift;
            log "$result"
        }
    })
    AE::cv->recv()

If you set a callback on a CondVar, then the callback will be called once the CondVar is ready (which will only happen after you start the event loop).

In the callback, $@ will contain any error, otherwise the result (if any) will be the first value in @_.

Once you set a callback on a CondVar, it will not be aborted when it goes out of scope.

Fire-and-Forget

    $e->delete_index(index=>'foo');

If a request is called in void context, then it will be executed once the event loop is started. No errors will be thrown, even if the request does not complete succesfully.

It will not be aborted with a change in scope, because there is no scope. If you exit the application without running an event loop, then any pending requests will not be run.

BLOCKING METHODS

"scrolled_search()" in ElasticSearch and "reindex()" in ElasticSearch will be executed synchronously.

SETTINGS

See AnyEvent::Curl::Multi for an explanation of the max_concurrency(), max_redirects(), proxy() and ip_resolve()

SEE ALSO

1;

Something went wrong with that request. Please try again.