PHP code example of makinacorpus / elasticsearch-query

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

    

makinacorpus / elasticsearch-query example snippets


// Create a query.
$query = new RootBoolQuery();

// Add some filters.
$query->must()->term('statut', 20);

// Create a nested bool query, for nested objects.
$nested = $query->must()->createNestedBool('statut_histo');
$nested->must()->term('statut_histo.statut', 23);

// Set some query options.
$query->size(100);
$query->from(0);
$query->trackTotalHits();

// Add some sorts.
$query->sort('pushed_at');
$query->sort('created_at');

\json_encode($query->build(), JSON_PRETTY_PRINT);