
== Quickstart

This section will give you a quick overview of the client and how the major functions work.

=== Installation

* Include elasticsearch-php in your `composer.json` file:
+
[source,json]
----------------------------
{
    "require": {
        "elasticsearch/elasticsearch": "~1.0"
    }
}
----------------------------

* Install the client with composer:
+
[source,shell]
----------------------------
curl -s http://getcomposer.org/installer | php
php composer.phar install
----------------------------

* Include the autoloader in your main project (if you haven't already), and instantiate a new client :
+
[source,php]
----------------------------
require 'vendor/autoload.php';

$client = new Elasticsearch\Client();
----------------------------


=== Index a document

In elasticsearch-php, almost everything is configured by associative arrays.  The REST endpoint, document and optional parameters - everything is an associative array.

To index a document, we simply specify a `body` that contains the document that we wish to index.  Each field in the document is represented by a different key/value pair in the associative array.

The index, type and ID are also specified in the parameters assoc. array:

[source,php]
----------------------------
$params = array();
$params['body']  = array('testField' => 'abc');
$params['index'] = 'my_index';
$params['type']  = 'my_type';
$params['id']    = 'my_id';
$ret = $client->index($params);
----------------------------

=== Get a document

Let's get the document that we just indexed:

[source,php]
----------------------------
$getParams = array();
$getParams['index'] = 'my_index';
$getParams['type']  = 'my_type';
$getParams['id']    = 'my_id';
$retDoc = $client->get($getParams);
----------------------------

=== Search for a document

Searching is a hallmark of elasticsearch, so let's perform a search.  We are going to use the Match query as a demonstration:

[source,php]
----------------------------
$searchParams['index'] = 'my_index';
$searchParams['type']  = 'my_type';
$searchParams['body']['query']['match']['testField'] = 'abc';
$retDoc = $client->search($searchParams);
----------------------------

=== Delete a document

Alright, let's go ahead and delete the document that we added previously:

[source,php]
----------------------------
$deleteParams = array();
$deleteParams['index'] = 'my_index';
$deleteParams['type'] = 'my_type';
$deleteParams['id'] = 'my_id';
$retDelete = $client->delete($deleteParams);
----------------------------

=== Delete an index

Due to the dynamic nature of elasticsearch, the first document we added automatically built an index with some default settings.  Let's delete that index because we want to specify our own settings later:

[source,php]
----------------------------
$deleteParams = array();
$deleteParams['index'] = 'my_index';
$client->indices()->delete($deleteParams);
----------------------------

=== Create an index

Ok, now that we are starting fresh, let's add a new index with some custom settings:

[source,php]
----------------------------
$indexParams['index'] = 'my_index';
$indexParams['body']['settings']['number_of_shards'] = 2;
$indexParams['body']['settings']['number_of_replicas'] = 0;
$client->indices()->create($indexParams);
----------------------------

=== Wrap up

That was just a crash-course overview of the client and it's syntax.  If you are familiar with elasticsearch, you'll notice that the methods are named just like REST endpoints.

You'll also notice that the client is configured in a manner that facilitates easy discovery via your IDE.  All core actions are available under the `$client` object (indexing, searching, getting, etc).  Index and cluster management are located under the `$client->indices()` and `$client->cluster()` objects, respectively.

Check out the rest of the Documentation to see how the entire client works.

