PHP code example of ulff / elasticsearch-php-client-bundle

1. Go to this page and download the library: Download ulff/elasticsearch-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/ */

    

ulff / elasticsearch-php-client-bundle example snippets


// app/AppKernel.php

public function registerBundles()
{
    $bundles = [
        // ...
        new Ulff\ElasticsearchPhpClientBundle\UlffElasticsearchPhpClientBundle(),
    ];

    // ...
}

$client = $this->get('ulff_elasticsearch_php_client.client');

$indexParams = new IndexParams('index-name', 'type-name', 'id');
$indexParams->setBody(['someField' => 'some value']);
$response = $client->index($indexParams);

$getParams = new GetParams('index-name', 'type-name', 'id');
$response = $client->get($getParams);

$deleteParams = new DeleteParams('index-name', 'type-name', 'id');
$response = $client->delete($deleteParams);

$deleteParams = new DeleteByQueryParams('index-name', 'type-name');
$deleteParams->setBody([
   'query' => [
       'match_all' => new \stdClass(),
   ]
]);
$response = $client->deleteByQuery($deleteParams);

$searchParams = new SearchParams('index-name', 'type-name');
$searchParams->setBody([
    'query' => [
        'match' => [
            'someField' => 'some value'
        ]
    ]
]);
$response = $client->search($searchParams);

$updateParams = new UpdateParams('index-name', 'type-name', 'id');
$updateParams->setBody(['someField' => 'some value']);
$response = $client->update($updateParams);

$purger = $this->get('ulff_elasticsearch_php_client.purger');
$purger->purgeIndex('index_name');

php composer.phar 
ulff_elasticsearch_php_client.purger