PHP code example of everzel / elasticsearch-query-builder
1. Go to this page and download the library: Download everzel/elasticsearch-query-builder library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
everzel / elasticsearch-query-builder example snippets
use Everzel\ElasticsearchQueryBuilder\Aggregations\MaxAggregation;
use Everzel\ElasticsearchQueryBuilder\Builder;
use Everzel\ElasticsearchQueryBuilder\Queries\MatchQuery;
$client = Elasticsearch\ClientBuilder::create()->build();
$companies = (new Builder($client))
->index('companies')
->addQuery(MatchQuery::create('name', 'spatie', fuzziness: 3))
->addAggregation(MaxAggregation::create('score'))
->search();
use Everzel\ElasticsearchQueryBuilder\Queries\RangeQuery;
use Everzel\ElasticsearchQueryBuilder\Builder;
$client = Elasticsearch\ClientBuilder::create()->build();
$builder = new Builder($client);
$builder->addQuery(RangeQuery::create('age')->gte(18));
$results = $builder->search(); // raw response from ElasticSearch
use Everzel\ElasticsearchQueryBuilder\Aggregations\TermsAggregation;
use Everzel\ElasticsearchQueryBuilder\Builder;
$results = (new Builder(Elasticsearch\ClientBuilder::create()->build()))
->addAggregation(TermsAggregation::create('genres', 'genre'))
->search();
$genres = $results['aggregations']['genres']['buckets'];