PHP code example of iboxs / elasticsearch

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

    

iboxs / elasticsearch example snippets


    //config = 
    $builder = Factory::builder($config);

    'providers' => [
        Iboxs\ElasticSearch\Laravel\ElasticsearchOrm\OrmProvider::class,
    ] 

    $builder = app(\Iboxs\ElasticSearch\Builder::class);

    $builder->index('index')->create(['key' => 'value']);
    //return collection
    $builder->index('index')->createCollection(['key' => 'value']);

    $builder->index('index')->update(['key' => 'value']) : bool

    $builder->index('index')->delete($id) : bool

    //select one
    $builder->index('index')->first();
    //select all
    $builder->index('index')->get();
    //select with paginate
    $builder->index('index')->paginate($page, $size) : Collection
    //select by id
    $builder->byId($id) : stdClass
    //select by id if failed throw error
    $builder->byIdOrFail($id) : stdClass
    //select chunk
    $builder->chunk(callback $callback, $limit = 2000, $scroll = '10m')

    $builder->count() : int

    $builder->whereTerm('key', 'value');

    //value without add wildcard '*'
    $builder->whereLike('key', 'value');

    $builder->whereMatch('key', 'value');

    $builder->whereBetween('key', ['value1', 'value2']);

    $builder->whereIn('key', ['value1', 'value2', ...]);

    $builder->where(function(Builder $query){
        $query->whereTerm('key', 'value');
    });

    $builder->where('key', '=', 'value');