Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/erichard/elasticsearch-query-builder
Build query for an ElasticSearch client using a fluent interface
https://github.com/erichard/elasticsearch-query-builder
elasticsearch php querybuilder
Last synced: 1 day ago
JSON representation
Build query for an ElasticSearch client using a fluent interface
- Host: GitHub
- URL: https://github.com/erichard/elasticsearch-query-builder
- Owner: erichard
- License: mit
- Created: 2018-02-07T14:04:31.000Z (almost 7 years ago)
- Default Branch: main
- Last Pushed: 2024-06-24T09:22:47.000Z (6 months ago)
- Last Synced: 2024-12-25T13:08:00.783Z (9 days ago)
- Topics: elasticsearch, php, querybuilder
- Language: PHP
- Size: 164 KB
- Stars: 39
- Watchers: 9
- Forks: 20
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
ElasticSearch Query Builder
===========================![img](https://img.shields.io/badge/phpstan-8-green)
![php](https://img.shields.io/badge/php-8.0-brightgreen)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](https://github.com/erichard/elasticsearch-query-builder/issues/7) for the roadmap.
Installation
------------```bash
composer require erichard/elasticsearch-query-builder "^3.0@beta"
```Usage
-----```php
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:
```php
$query = new BoolQuery(must: [
new RangeQuery(
field: 'price',
gte: 100
),
new RangeQuery(
field: 'stock',
gte: 10
),
]);
```or with the factory
```php
$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`