PHP code example of xdm / elastic

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

    

xdm / elastic example snippets


use Xdm\Elastic\Elastic;

//construct set host
$elastic = new Elastic($host);

//set index
$elastic->index($index);

//set type
$elastic->type($type);

//add where conditon filter
$elastic->where(['key' => 'value']);

//add whereIn conditon filter
$elastic->whereIn('key', ['value1', 'value2']);

//add range condition filter
$elastic->range('key', ['gte' => 'value1', 'lte' => 'value2']);

//set size
$elastic->take(100);

//add Aggregation
$elastic->count($field);
$elastic->groupBy($field);
$elastic->sum($field);
$elastic->max($field);
$elastic->min($field);
$elastic->avg($field);

//set order
$elastic->orderBy($field, 'desc');

//send query and get response
$response = $elastic->search();