Installationedit
Elasticsearch-php only has a three requirements that you need to worry about:
The rest of the dependencies will automatically be downloaded and installed by Composer. Composer is a package and dependency manager for PHP. Installing elasticsearch-php with Composer is very easy
Version Matrixedit
Since there are breaking changes in Elasticsearch 1.0, you need to match your version of Elasticsearch to the appropriate version of this library.
If you are using a version older than 1.0, you must install the 0.4
Elasticsearch-PHP branch. Otherwise, use the 1.0
branch.
The master branch will always track Elasticsearch master, but it is not recommended to use dev-master
in your production code.
Elasticsearch Version | Elasticsearch-PHP Branch |
---|---|
>= 1.0 |
|
⇐ 0.90.* |
|
Composer Installationedit
Include elasticsearch-php in your
composer.json
file. If you are starting a new project, simply paste the following JSON snippet into a new file calledcomposer.json
. If you have an existing project, include this requirement under the rest of requirements already present:{ "require": { "elasticsearch/elasticsearch": "~0.4" } }
Install the client with composer. The first command download the
composer.phar
PHP package, and the second command invokes the installation. Composer will automatically download any required dependencies, store them in a /vendor/ directory and build an autoloader.:curl -s http://getcomposer.org/installer | php php composer.phar install --no-dev
Finally, include the generated autoloader in your main project. If your project is already based on Composer, the autoloader is likely already included somewhere and you don’t need to add it again. Finally, instantiate a new client:
require 'vendor/autoload.php'; $client = new Elasticsearch\Client();
More information about Composer can be found at their website.
--no-dev flagedit
You’ll notice that the installation command specified --no-dev
. This prevents Composer
from installing the various testing and development dependencies. For average users, there
is no need to install the test suite. In particular, the development dependencies include
a full copy of Elasticsearch so that tests can be run against the REST specifications This
is a rather large download for non-developers, hence the --no-dev flag
If you wish to contribute to development of this library, just omit the --no-dev
flag to
be able to run tests.