Elasticsearch Object Mapper. Includes integration with Symfony 2.7+ and Zend Framework 3.
composer require pgs-soft/elastic-om
Elasticsearch type(s) are configured basing on entities annotations, e.g.
use Pgs\ElasticOM\Annotation as ODM;
class Book
{
/**
* @var string
* @ODM\Id
* @ODM\Field(type="string")
*/
private $id;
/**
* @var Author
* @ODM\Field(type="nested", targetClass="AppBundle\Entity\Author")
*/
private $author;
/**
* @var string
* @ODM\Field(type="string")
*/
private $title;
// ...
}
use Pgs\ElasticOM\ElasticApi\ApiServiceFactory;
$api = ApiServiceFactory::create('localhost', '9200', 'elastic_om');
// creating index 'elastic_om'
$api->createIndex();
// creating type Book
$api->createType(Book::class);
// updating type Book
$api->updateType(Book::class);
Marks class property to be used as unique object identifier. Only one property can be marked as Id.
Specifies property to be mapped into elasticsearch type. Available parameters:
- type - elasticsearch mapping type for the property. List of all types can be found here: https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-types.html
- targetClass - if type is object or nested, targetClass specifies nested object class
// app/AppKernel.php
public function registerBundles()
{
$bundles = [
// ...
new Pgs\ElasticOM\Bridge\Symfony\ElasticOMBundle(),
// ...
];
}
# app/config.yml
elastic_om:
host: 'localhost'
port: 9200
index: 'elastic_om'
$slug = $this->get('elastic_om.entity_repository_manager')
->getRepository(Author::class)
->update(new Author());
// config/modules.config.php
return [
// ...
'Pgs\ElasticOM\Bridge\ZF3',
];
// module/Application/config/module.config.php
'controllers' => [
'factories' => [
ExampleController::class => function ($em) {
return new ExampleController($em->get('elastic_om.entity_repository_manager'));
},
],
],
// config/module.config.php
return [
// ...
'elastic_om' => [
'host' => 'localhost',
'port' => '9200',
'index' => 'elastic_om',
],
// ...
];
Bug reports and pull requests are welcome on GitHub at https://github.com/PGSSoft/ElasticOM.
The project maintained by software development agency PGS Software. See our other open-source projects or contact us to develop your product.