SherlockPHP

What is Sherlock?

Sherlock is a PHP (>=5.3.0) client for ElasticSearch Sherlock provides an easy, simple interface to search and manage your ElasticSearch cluster.

Philosophy

Sherlock aims to continue the precendent set by ElasticSearch: work out of the box with minimal configuration and provide a simple interface.

The developer should never need to stop and look up a class name to instantiate, or dig through docs to remember which class accepts which arguments.

Flexibility

While Sherlock provides a powerful ORM-like interface to managing ElasticSearch, we recognize that an ORM is not always convenient.

Where possible, Sherlock methods are compatible with raw associative arrays, or even plain JSON. Use as much, or as little, of the ORM as you need.


Fork on Github
//Build a new search request
$request = $sherlock->search();
//populate a Term query to start
$termQuery = Sherlock::queryBuilder()->Term()
                                    ->field("message")
                                    ->term("ElasticSearch")

//Set the index, type and from/to parameters of the request.
$request->index("test")
        ->type("tweet")
        ->from(0)
        ->to(10);
        ->query($termQuery);

//Execute the search and return results
$response = $request->execute();
echo "Took: ".$response->took."\r\n";
echo "Number of Hits: ".count($response)."\r\n";

//Iterate over the hits and print out some data
foreach($response as $hit)
{
    echo $hit['score'].' - '.$hit['source']['message']."\r\n";
}