Skip to content

CodeDuck42/elasticsearch

Repository files navigation

latest stable version license php version codecov infection unit tests psalm elasticsearch

Minimalistic elasticsearch client

Born out of frustration about the dependency hell of the available client packages. I didn't need a library with all the features, as a result this package was born. It provides the bare minimum to index, delete and query documents.

This library is compatible with elasticsearch 6.x and 7.x and has no dependencies on the official elasticsearch client packages.

All issues should go to the issue tracker from github.

Features

  • Adding a document to an elasticsearch index
  • Delete a document from an elasticsearch index
  • Send multiple adding and delete actions as a bulk action
  • Run a query on an elasticsearch index

Usage

use CodeDuck\Elasticsearch\Client;
use CodeDuck\Elasticsearch\SimpleClient;
use Symfony\Component\HttpClient\HttpClient;

$client = new SimpleClient(
    new Client(HttpClient::create(), 'http://127.0.0.1:9200'),
    'my-index', '_doc'
);

$client->begin();
$client->add('ID-123', ['name' => 'foo', 'foo' => 12345]);
$client->add('ID-234', ['name' => 'bar', 'foo' => 12345]);
$client->commit();

$result = $client->query(['query' => ['term' => ['name' => 'bar']]]);

foreach ($result->getDocuments() as $document) {
    echo json_encode($document->getSource(), JSON_THROW_ON_ERROR) . PHP_EOL;
}

$client->begin();
$client->delete('ID-123');
$client->delete('ID-234');
$client->commit();

More detailed examples can be found here: full client, simple client.

TODO

  • Complete documentation
  • Actions should return the response from elasticsearch, especially for bulk actions
  • Investigating options for authentication besides username and password in the server url (necessary?)

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages