PHP code example of elastification / php-client-bundle

1. Go to this page and download the library: Download elastification/php-client-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

elastification / php-client-bundle example snippets


/** @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());

/** @var DocumentRepositoryInterface $docRepo */
$docRepo = $this->get('elastification_php_client.repository.document');

var_dump($docRepo->get('my-index', 'my-type', 'yourDocumentId'));

/** @var IndexRepositoryInterface $indexRepo */
$indexRepo = $this->get('elastification_php_client.repository.index');
var_dump($indexRepo->exists('my-index'));

/** @var IndexRepositoryInterface $indexRepo */
$indexRepo = $this->get('elastification_php_client.repository.index');
var_dump($indexRepo->create('my-index'));

/** @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']

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 }

$request = $client->getRequest('get.service.text');
$request->setId('yourDocumentId');
$response = $client->send($request);
var_dump($response->getData()->getGatewayValue());
"elastification/php-client-bundle": "<1.0"
"munkie/elasticsearch-thrift-php": "~1.4"
yml
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}