leslie-xy / elasticsearch
elasticsearc模型包
Requires
- php: >=7.0.0
- ext-json: *
- anlutro/curl: ^1.4
- laravel/framework: >=5.5
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.15
- squizlabs/php_codesniffer: ^3.4
This package is auto-updated.
Last update: 2025-03-18 12:31:08 UTC
README
use Leslie\elasticsearch\Repository\ElasticSearch\ElasticSearchModel;
$this->model = with(new ElasticSearchModel($this->index, $this->type));
get()
$sessionData = $this->model->get();
where()
$this->model->where['query']['bool']['filter'][] = ['range' => [$field => $data]];
$this->model->where['query']['bool']['filter'][] = ['term' => [$field => $data]];
$this->model->where['query']['bool']['filter'][] = ['terms' => [$field => $data]];
script: Two-field computation where
$this->model->where['query']['bool']['filter'][] = ['script' => ['script' => ['inline' => "(doc['start_talking_at_es'].value - doc['created_at_es'].value) < 30", 'lang' => 'painless']]];
field()
$this->model->field['_source'] = ['includes' => $field];
group()
$this->model->group = ['aggs' => [$aggsName => ['terms'=> ['field' => $aggsName, 'size' => $size]]]];
if (!empty($aggsArr)){
$this->model->group['aggs'][$aggsName]['aggregations'] = $aggsArr;
}
aggs原生
$this->model->group['aggs'] = ['esim_ids' => ['terms' => ['field' => 'esim_id', 'size' => 10000, 'order' => ['max_time' => 'desc']], 'aggs' => ['max_time' => ['max' => ['field' => 'create_time']]]]];
paginate()
$obuVideo['list'] = $this->model->paginate($page); $obuVideo['page_count'] = $this->model->page_count; $obuVideo['page'] = $page;
create()
插入数据
$this->model->create($insertData, 'id');
saveModel()
修改数据
$this->model->saveModel($updateData, 'id');
delete()
删除数据
$this->model->delete($deleteId);
createTable()
创建索引
$model = with(new ElasticSearchModel('saas', 'knowledge_base'));
$field = [
'id' => ['type' => 'integer'],
'title' => ['type' => 'text'],
'problem_id' => ['type' => 'integer'],
'content' => ['type' => 'text'],
'engineer_code' => ['type' => 'text'],
'updated_at' => ['type' => 'text'],
'created_at' => ['type' => 'text'],
];
$model->createTable('saas', 'knowledge_base', $field);