PHP code example of ccennis / larelastic

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

    

ccennis / larelastic example snippets


 Larelastic\Elastic\Providers\ElasticServiceProvider::class
 

'Elastic' => Larelastic\Elastic\Facades\Elastic::class
 

 php artisan vendor:publish
 

ELASTICSEARCH_HOST=http://elastic:9200
ELASTICSEARCH_PORT=9200
SCOUT_DRIVER=elastic
SCOUT_ELASTIC_HOST=http://elastic:9200
 
 artisan scout:import "App\Models\Tattoo"


$response = Tattoo::search()->where('name', 'mold')->get();
$response = Tattoo::search()->where('name', '=', 'mold')->get();




$response = Tattoo::search()->orWhere(['name', '=', 'mold'],['name', '=', 'Element'])->get();




$response = Tattoo::search()->orWhere(function($query, $boolean){
            $query->where('name', '=','Mold', $boolean)
            ->where('model', '=','test', $boolean);
            return $query;
        })->orWhere(function($query, $boolean){
            $query->where('name', '=','element', $boolean)
            ->where('model', '=','test', $boolean);
            return $query;
        })->get();




 $response = Tattoo::search()->whereMulti(['name', 'model'],'=','Mold')->get();
 


 $response = Tattoo::search()->whereMulti(['name', 'model'],'=','Mold', 'best_fields')->get();
 


 $response = Tattoo::search()->whereMulti(['name', 'model'],'=','Mold')->paginate(20);
 

$response = Tattoo::search()->where('name', 'mold')
sort->('name','desc')->get()

$response = Tattoo::search()->where('name', 'mold')
sort->('name', 'desc', 'keyword')->get()

$data = [
                'field' => 'location_lat_long', 
                'lat' => $lat,
                'long' => $lat,
            ];

            $this->search->buildGeoSort($data);

        $latLongArray = explode(",", $this->user->location_lat_long);

        $response['bool']['must'] = $this->search->whereDistanceSyntax('artist.location_lat_long', $latLongArray[0], $latLongArray[1], '25mi');

        return $response;


mi (miles), in (inches), yd (yards), km (kilometers), cm (centimeters), mm (millimeters).


#### <a id="aggs"></a>Aggregation (aggs)


 php artisan make:index-configurator TattooIndexConfigurator

php artisan make:searchable-model Product --index-configurator=TattooIndexConfigurator

php artisan elastic:create-index "App\Models\Tattoo"

php artisan elastic:update-mapping "App\\Models\MyModel"

php artisan elastic:update-index "App\Models\MyModelConfigurator"

php artisan elastic:drop-index "App\Models\MyModel"

public function searchableQuery()
{
    return $self->newQuery();
}
json
{

php

$response = Tattoo::search()->where('name', 'mold')
->rollup('card_color')->get();