Elasticsearch Object Mapper for PHP 7
PHP
Permalink
Failed to load latest commit information.
src
tests
.gitattributes
.gitignore
.travis.yml
LICENSE
README.md
composer.json

README.md

PGS Software / ElasticOM

Latest Stable Version PHP Version License Build Status Code Coverage Code Quality

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:

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.

Follow us

Twitter URL Twitter Follow