PHP code example of askonaweb / elastic-query-builder

1. Go to this page and download the library: Download askonaweb/elastic-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/ */

    

askonaweb / elastic-query-builder example snippets


use AskonaWeb\ElasticQueryBuilder\Aggregations\MaxAggregation;
use AskonaWeb\ElasticQueryBuilder\Builder;
use AskonaWeb\ElasticQueryBuilder\Queries\NestedQuery;
use AskonaWeb\ElasticQueryBuilder\Queries\TermQuery;
use AskonaWeb\ElasticQueryBuilder\Sorts\Sort;

$requestParams = Builder::create()
    ->index("indexName")
    ->addQuery(NestedQuery::create("path.to.something", TermQuery::create("field", "value")))
    ->addSort(Sort::create("sortfield", Sort::ASC))
    ->addAggregation(MaxAggregation::create("agg_max_score", "myscore"))
    ->getRequestParams();