PHP code example of artpapanyan / elasticsearch
1. Go to this page and download the library: Download artpapanyan/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/ */
artpapanyan / elasticsearch example snippets
use Elastic\Elasticsearch\ClientBuilder;
use Elastic\Elasticsearch\Response\Elasticsearch;
use Http\Mock\Client;
use Nyholm\Psr7\Response;
$mock = new Client(); // This is the mock client
$client = ClientBuilder::create()
->setHttpClient($mock)
->build();
// This is a PSR-7 response
$response = new Response(
200,
[Elasticsearch::HEADER_CHECK => Elasticsearch::PRODUCT_NAME],
'This is the body!'
);
$mock->addResponse($response);
$result = $client->info(); // Just calling an Elasticsearch endpoint
echo $result->asString(); // This is the body!
$response = $this->createMock('Psr\Http\Message\ResponseInterface');