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

ElasticSearch operates through a JSON protocol. While the JSON format is great for testing new queries on the commandline, it is very verbose and unpleasant to write in scripts and applications. Multi-line JSON strings are error prone, difficult to read and have zero syntax-highlighting/type-hinting from your IDE

Sherlock provides a relatively lightweight wrapper over the ElasticSearch API protocol. It provides a one-to-one mapping to the underlying API, using as similar of names as possible. Unlike a simple wrapper, we have included certain functionality that is useful to all users of ElasticSearch (such as automatic round-robin requests to the cluster, etc).

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

Sherlock strongly believes that the developer has enough to remember with their own code. Sherlock goes to great lengths to simplify the interface between developer and ElasticSearch to a few simple classes. 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.

With that in mind, however, it is clear that simple interfaces will not provide the needs of all developers. Should it be nescessary, developers can surface more advanced features out of the Sherlock core. These capabilities are documented in the Sherlock document, but not necessarily "advertised" by the main Sherlock object.

We want to keep the main interface clean and accessible for the 90% scenarios while providing full capability for the final 10% edge cases.

Regarding programatic style, Sherlock tries to adhere to a style of method chaining and "Fluid" interface. Internally, magic methods and type-hinting are relied upon heavily to provide a flexible and intuitive API that minimizes the number of classes that need to be remembered

We love Sherlock...

...but maybe you wont. That certainly makes us sad, and we'd love to know why (submit an issue or write an email on the list!), but it's a situation that is understandable. A library can't be everything for everyone.

There are a couple other PHP client libraries for ElasticSearch, in varying states of maturity and capability:

  • Elastica - A fairly mature and well tested library. Uses a more verbose "Zend" style interface. Actively maintained.
  • ElasticSearch - Barebones wrapper on top of cURL. All commands/queries are formulated using associative arrays. Actively maintained.

If you run into trouble, we'd love to help!

Since the documentation is still actively being created, and Sherlock is undergoing a lot of changes due to it's young nature, you will probably have questions. There are three great places to get my attention:

  • Ping me on Twitter @ZacharyTong - I keep an eye on my Twitter account, so drop me a message at any time
  • The SherlockPHP Email List - Probably the best place for discussions, bug reports or general questions.
  • #ElasticSearch or #SherlockPHP on Freenode - I idle in both channels as "polyfractal", feel free to ping me whenever!
  • File an Issue - Issues are closely monitored, so if you've run into a bug, file it there! If you just have a question, try email or IRC first.