PHP code example of greensight / laravel-elastic-query
1. Go to this page and download the library: Download greensight/laravel-elastic-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/ */
greensight / laravel-elastic-query example snippets
use Greensight\LaravelElasticQuery\ElasticIndex;
class ProductsIndex extends ElasticIndex
{
protected string $name = 'test_products';
protected string $tiebreaker = 'product_id';
}
$searchQuery->sortBy('field', 'desc', 'max'); // field is from main document
$searchQuery->sortByNested(
'nested_field',
fn(SortableQuery $subQuery) => $subQuery->where('field_in_nested', 'value')->sortBy('field')
);