erichard / elasticsearch-query-builder
Create elastic search query with a fluent interface
Installs: 241 103
Dependents: 1
Suggesters: 0
Security: 0
Stars: 39
Watchers: 9
Forks: 20
Open Issues: 4
Requires
- php: >=8.0
Requires (Dev)
- phpstan/phpstan: ^1.4.10
- phpstan/phpstan-deprecation-rules: ^1.0.0
- phpstan/phpstan-phpunit: ^1.0.0
- phpunit/phpunit: ^9.5.19
- rector/rector: ^0.12.17
- symplify/easy-coding-standard: ^10.1
This package is auto-updated.
Last update: 2024-10-14 12:00:39 UTC
README
This is a PHP library which helps you build query for an ElasticSearch client by using a fluent interface.
WARNING: This branch contains the next 3.x release. Check the corresponding issue for the roadmap.
Installation
composer require erichard/elasticsearch-query-builder "^3.0@beta"
Usage
use Erichard\ElasticQueryBuilder\QueryBuilder; use Erichard\ElasticQueryBuilder\Aggregation\Aggregation; use Erichard\ElasticQueryBuilder\Filter\Filter; $qb = new QueryBuilder(); $qb ->setIndex('app') ->setSize(10) ; // Add an aggregation $qb->addAggregation(Aggregation::terms('agg_name', 'my_field')); $qb->addAggregation(Aggregation::terms('agg_name_same_as_field')); // Set query $qb->setQuery(Query::terms('field', 'value')); // I am using a client from elasticsearch/elasticsearch here $results = $client->search($qb->build());
with PHP 8.1 you can use named arguments like this:
$query = new BoolQuery(must: [ new RangeQuery( field: 'price', gte: 100 ), new RangeQuery( field: 'stock', gte: 10 ), ]);
or with the factory
$query = Query::bool(must: [ Query::range( field: 'price', gte: 100 ), Query::range( field: 'stock', gte: 10 ), ]);
Contribution
- Use PHPCS fixer and PHPStan
composer lint
- Update tests (PHPUnit)
composer test