Skip to content

StarveTheEgo/elasticsearch-query-builder

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 

Repository files navigation

ElasticSearch Query Builder

This is a PHP library which helps you build query for an ElasticSearch client by using a fluent interface.

Installation

$ composer require erichard/elasticsearch-query-builder

Usage


use Erichard\ElasticQueryBuilder\QueryBuilder;
use Erichard\ElasticQueryBuilder\Aggregation\Aggregation;
use Erichard\ElasticQueryBuilder\Filter\Filter;

$qb = new QueryBuilder();

$qb
    ->setType('my_type')
    ->setIndex('app')
    ->setSize(10)
;

// Add an aggregation
$qb->addAggregation(Aggregation::terms('agg_name')->setField('my_field'));

// Add a filter
$boolFilter = Filter::bool();
$boolFilter->addFilter(Filter::terms()->setField('field')->setValue($value));


$qb->addFilter($boolFilter);

// I am using a client from elasticsearch/elasticsearch here
$results = $client->search($qb->getQuery());

About

Build query for an ElasticSearch client using a fluent interface

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%