Here is the configuration section for using the bundle
Required in composer.json
"elastification/php-client-bundle": "<1.0"
You have choose the right package for your transport. If you do not have installed thrift you should use guzzle
"guzzlehttp/guzzle": "<7.0"
For Thrift transport
"munkie/elasticsearch-thrift-php": "~1.4"
Don't forget to run composer update after you finished your composer.json
In your app/config/AppHernel.php file you should activate the bundle by adding it to the array
$bundles[] = new Elastification\Bundle\ElastificationPhpClientBundle\ElastificationPhpClientBundle();
In your app/config.yml or environment based you can add params (full config example):
elastification_php_client:
host: 127.0.0.1
port: 9200
protocol: http # http/thrift
elasticsearch_version: 1.4.1
search_repository_serializer_dic_id: elastification_php_client.serializer.native #default: elastification_php_client.serializer.native
index_repository_serializer_dic_id: elastification_php_client.serializer.native #default: elastification_php_client.serializer.native
document_repository_serializer_dic_id: elastification_php_client.serializer.native #default: elastification_php_client.serializer.native
replace_version_of_tagged_requests: true #default: false
logging_enabled: true
profiler_enabled: true
jms_serializer_class_map:
- {index: my-index, type: my-type, class: AppBundle\Entity\MyEntity}
The registered DIC service id for the client is elastification_php_client
Native Serializer Service Id: elastification_php_client.serializer.native
Jms Serializer Search Service Id: elastification_php_client.serializer.jms.search
Jms Serializer Document Service Id: elastification_php_client.serializer.jms.document
Document Repository Serivce Id: elastification_php_client.repository.document
Search Repository Serivce Id: elastification_php_client.repository.search
Index Repository Serivce Id: elastification_php_client.repository.index
Cat Repository Serivce Id: elastification_php_client.repository.cat
If you want to register request services you can tag them with: elastification_php_client.request
For all examples should create some sample data in your elasticsearch.
Performs a simple search. This code is an example that can be performed within an action of a controller.
/** @var SearchRepositoryInterface $searchRepo */
$searchRepo = $this->get('elastification_php_client.repository.search');
$query = array(
'query' => array(
'term' => array(
'country' => array(
'value' => 'germany'
)
)
)
);
$searchRepo->search('my-index', 'my-type', $query);
var_dump($response->getHits());
Gets a single document by id. This code is an example that can be performed within an action of a controller.
/** @var DocumentRepositoryInterface $docRepo */
$docRepo = $this->get('elastification_php_client.repository.document');
var_dump($docRepo->get('my-index', 'my-type', 'yourDocumentId'));
Checks if an index exists This code is an example that can be performed within an action of a controller.
/** @var IndexRepositoryInterface $indexRepo */
$indexRepo = $this->get('elastification_php_client.repository.index');
var_dump($indexRepo->exists('my-index'));
Creates an index This code is an example that can be performed within an action of a controller.`
/** @var IndexRepositoryInterface $indexRepo */
$indexRepo = $this->get('elastification_php_client.repository.index');
var_dump($indexRepo->create('my-index'));
This code is an example that can be performed within an action of a controller.
/** @var Client $client */
$client = $this->get('elastification_php_client');
$request = new SearchRequest('my-index', 'my-type', new NativeJsonSerializer());
$response = $client->send($request);
//get the raw deserialized data
var_dump($response->getData()->getGatewayValue());
//for grabbing into the result do: $response->getData()['hits']
Here is an example of a tagged request as service. The id parameter is optional. If this is not set, the request service id will be used. If the config parameter replace_version_of_tagged_requests is set to true. All registered requests will be parsed and set to the configured version.
request.getdocument:
class: "Elastification\Client\Request\V090x\GetDocumentRequest"g
arguments: ["my-index", "my-type", @elastification_php_client.serializer.native]
public: false
tags:
- { name: elastification_php_client.request, id: get.service.text }
Using a registered request and perform a request. This code is an example that can be performed within an action of a controller.
$request = $client->getRequest('get.service.text');
$request->setId('yourDocumentId');
$response = $client->send($request);
var_dump($response->getData()->getGatewayValue());
- create version for lib (0.1.0)
- create version for bundle
- [] implement thrift config
- create jms serializer services
- create services for document repository
- create services for search repository
- create jms serializer service if jms serializer is available
- client lib: create jms document entity
- create document jms serializer service
- [] php-client enable/disable response (debug) output ?