erichard/elasticsearch-query-builder
最新稳定版本:3.2.0
Composer 安装命令:
composer require erichard/elasticsearch-query-builder
包简介
Create elastic search query with a fluent interface
README 文档
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
统计信息
- 总下载量: 332.73k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 39
- 点击次数: 2
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-01-04