pgs-soft / elastic-om
Elasticsearch Object Mapper
v1.0.0
2016-12-06 12:32 UTC
Requires
- php: >=7
- doctrine/annotations: ^1
- elasticsearch/elasticsearch: ^2.2.2 | ^5
- zendframework/zend-hydrator: ^2
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2
- kubawerlos/types-checker: ^1.0.1
- matthiasnoback/symfony-config-test: ^2
- phpunit/phpunit: ^5.4.3
- squizlabs/php_codesniffer: ^2.7
- symfony/dependency-injection: ^2.7 | ^3
- symfony/http-kernel: ^2.7 | ^3
- zendframework/zend-servicemanager: ^3
This package is auto-updated.
Last update: 2024-12-05 19:54:42 UTC
README
Elasticsearch Object Mapper. Includes integration with Symfony 2.7+ and Zend Framework 3.
Installation
composer require pgs-soft/elastic-om
Entity type configuration
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; // ... }
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.
Field
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
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.
About
The project maintained by software development agency PGS Software. See our other open-source projects or contact us to develop your product.