PHP code example of royalcms / elasticsearch

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

    

royalcms / elasticsearch example snippets


$data = [
    'body' => [
        'testField' => 'abc'
    ],
    'index' => 'my_index',
    'type' => 'my_type',
    'id' => 'my_id',
];

$client = ClientBuilder::create()->build();
$return = $client->index($data);

$return = RC_Elasticsearch::index($data);

$return = RC_Elasticsearch::connection('connectionName')->index($data);

$stats = RC_Elasticsearch::indices()->stats(['index' => 'my_index']);
$stats = RC_Elasticsearch::nodes()->stats();
$stats = RC_Elasticsearch::cluster()->stats();

$response = RC_Elasticsearch::snapshots()->create($params);
$response = RC_Elasticsearch::snapshots()->restore($params);

$response = RC_Elasticsearch::indices()->delete(['index' => 'my_index']);
ini
ELASTICSEARCH_HOST=localhost
ELASTICSEARCH_PORT=9200
ELASTICSEARCH_SCHEME=http
ELASTICSEARCH_USER=
ELASTICSEARCH_PASS=