# php-elasticsearch-orm **Repository Path**: xpxw/php-elasticsearch-orm ## Basic Information - **Project Name**: php-elasticsearch-orm - **Description**: 为php提供elasticsearch的orm扩展包 - **Primary Language**: PHP - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 1 - **Created**: 2023-06-03 - **Last Updated**: 2023-06-03 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # PHP ELASTICSEARCH ORM ## Install ``` composer require vae/elasticsearchorm ``` ## Support Elasticsearch Version >more than 7.0 ## Use ### PHP ```php //require elasticsearch config $config = require "elasticsearch.php"; //instance $builder = Factory::builder($config); ``` ### Laravel framework Add the service provider config in `config/app.php` ```php 'providers' => [ Vae\PhpElasticsearchOrm\Laravel\ElasticsearchOrm\OrmProvider::class, ] ``` Use in Code ```php $builder = app(\Vae\PhpElasticsearchOrm\Builder::class); ``` ## Quickstart ### Create ```php $builder->index('index')->create(['key' => 'value']); //return collection $builder->index('index')->createCollection(['key' => 'value']); ``` ### Update ```php $builder->index('index')->update(['key' => 'value']) : bool ``` ### Delete ```php $builder->index('index')->delete($id) : bool ``` ### Select ```php //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') ``` ### Count ```php $builder->count() : int ``` ### Condition whereTerm ```php $builder->whereTerm('key', 'value'); ``` whereLike(wildcard) ```php //value without add wildcard '*' $builder->whereLike('key', 'value'); ``` match ```php $builder->whereMatch('key', 'value'); ``` range ```php $builder->whereBetween('key', ['value1', 'value2']); ``` where in ```php $builder->whereIn('key', ['value1', 'value2', ...]); ``` nested ```php $builder->where(function(Builder $query){ $query->whereTerm('key', 'value'); }); ``` ### Where Support Operator > ['=' => 'eq','>' => 'gt','>=' => 'gte','<' => 'lt','<=' => 'lte','!=' => 'ne',] ```php $builder->where('key', '=', 'value'); ``` ### More see file `Vae\PhpElasticsearchOrm\Builder`