PHP code example of kiwfy / simple-elasticsearch-php
1. Go to this page and download the library: Download kiwfy/simple-elasticsearch-php 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/ */
kiwfy / simple-elasticsearch-php example snippets
use SimpleElasticsearch\SimpleElasticsearch;
$host = 'http://localhost:9200/';
$elastic = new SimpleElasticsearch($host);
$elastic->setConnectionOptions([
'connect_timeout' => 5,
'timeout' => 5,
]);
...
$query = "SELECT * FROM test WHERE email LIKE '%[email protected]' ORDER BY email DESC";
$sqlResponse = $elastic->sql(
$query
);
var_dump($sqlResponse);
...
// var $sql has data returned from previous query with the cursor
$sqlCursorResponse = $elastic->sqlCursor(
$sql['cursor']
);
var_dump($sqlCursorResponse);
...
$query = "SELECT * FROM test WHERE email LIKE '%[email protected]' ORDER BY email DESC";
$translate = $elastic->translate(
$query
);
var_dump($translate);