, (*1)
Elasticsearch Object Mapper. Includes integration with Symfony 2.7+ and Zend Framework 3., (*2)
Installation
composer require pgs-soft/elastic-om
Entity type configuration
Elasticsearch type(s) are configured basing on entities annotations, e.g., (*3)
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;
// ...
}
Usage
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);
Available annotations
Id
Marks class property to be used as unique object identifier. Only one property can be marked as Id., (*4)
Field
Specifies property to be mapped into elasticsearch type. Available parameters:, (*5)
-
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
Integrations
Symfony
// 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());
Zend Framework 3
// 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',
],
// ...
];
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/PGSSoft/ElasticOM., (*6)
About
The project maintained by software development agency PGS Software.
See our other open-source projects or contact us to develop your product., (*7)
Follow us
, (*8)