mapado / elastica-query-bundle
Query builder bundle for ElasticSearch
Installs: 6 089
Dependents: 0
Suggesters: 1
Security: 0
Stars: 12
Watchers: 10
Forks: 2
Open Issues: 0
Requires
- php: ^7.2
- doctrine/common: ^2.0
- ruflin/elastica: ^2.2
- symfony/config: ^2.7|^3.0|^4.0
- symfony/dependency-injection: ^2.7|^3.0|^4.0
- symfony/http-kernel: ^2.7|^3.0|^4.0
Requires (Dev)
- mapado/php-cs-fixer-config: ^2.1
- phpstan/phpstan: ^0.10.1
- symfony/http-foundation: ^3.0
- symfony/stopwatch: ^3.0
README
Inspired by FOSElasticaBundle and Doctrine to create a query builder for ElasticSearch.
Installation
composer require "mapado/elastica-query-bundle:1.*"
Configuation
# app/config/config.yml mapado_elastica_query: clients: client_name: host: elasticsearch.example.com port: 9200 timeout: 3 indexes: twitter: # (optional, default to 'twitter') index_name: twitter_v1 client: client_name types: tweet: ~ document_managers: tweety: type: mapado.elastica.type.twitter.tweet # data_transformer: my.model.transformer #optional, must implements Mapado\ElasticaQueryBundle\DataTransformer\DataTransformerInterface # query_builder_classname: Acme\\Demo\\QueryBuilder\\TweetyQueryBuilder # @see "Overide Query Builder" section
Usage
Get DocumentManager
$client = $this->get('mapado.elastica.client.client_name'); // return a \Elastica\Client object $index = $this->get('mapado.elastica.index.twitter'); // return a \Elastica\Index object $type = $this->get('mapado.elastica.type.twitter.tweet'); // return a \Elastica\Type object
Get elastica objects
You can fetch basic Elastica objects just by doing this:
$documentManager = $this->get('mapado.elastica.document_manager.tweety'); // return a \Mapado\ElasticaQueryBundle\DocumentManager $queryBuilder = $documentManager->createQueryBuilder(); $queryBuilder->addQuery(new \Elastica\Query\Term(['field' => 'value'])) ->addFilter(new \Elastica\Filter\Term(['field' => 'value'])); ->setMaxResults(20) ->setFirstResults(40); $tweets = $queryBuilder->getResult(); // return a \Mapado\Elastica\Model\SearchResult
Overide Query Builder
You can override querybuilder doing this is your config file:
mapado_elastica_query: # ... document_managers: tweety: type: mapado.elastica.type.twitter.tweet query_builder_classname: 'Acme\Demo\QueryBuilder\TweetyQueryBuilder'
The QueryBuilder class must inherit from Mapado\ElasticaQueryBundle\QueryBuilder