PHP code example of janartist / elasticsearch

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

    

janartist / elasticsearch example snippets




declare(strict_types=1);

namespace App\EsModel;

use Janartist\Elasticsearch\Model;

class OrderModel extends Model
{
    /**
     * 索引
     * */
    protected $index = 'chungou-order';
    /**
     * 字段类型,创建索引中用
     * */
    protected $casts = ['name' => [
        "type" => "text",
        "analyzer" => "ik_max_word",
        "search_analyzer" => "ik_smart"
    ]];
}


   OrderModel::query()->where('name', 'zhangsan')->get();
   OrderModel::query()->where('name', 'zhangsan')->first();  
   OrderModel::query()->whereIn('name', ['zhangsan'])->first();        
   OrderModel::query()->whereLike('name', 'zhangsan')->first();  
   OrderModel::query()->find();       



     OrderModel::query()->create([]);
     OrderModel::query()->insert([[],[]]);
     OrderModel::query()->delete([], '23asdq');
     OrderModel::query()->update([], '23asdq');