syqmk / think-elasticsearch
A encapsulation interface for elasticsearch php api.
Installs: 19
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/syqmk/think-elasticsearch
Requires
- elasticsearch/elasticsearch: ~6.0.0
This package is not auto-updated.
Last update: 2025-12-21 11:22:49 UTC
README
目前根据开发时的实际业务,封装了部分方法,简化查询,会持续更新
以下类库都在
\\think\\elasticsearch命名空间下
说明
需要继承 \think\elasticsearch\ES 类,覆盖es配置
例如:
use think\elasticsearch\ES;
class Esdb extends ES {
protected $esHost = ['192.168.2.11'];
protected $esIndex = 'think';
protected $esType = 'user';
}
esGet
条件查询
例如:
$filter = [
'query' => [
"bool" => [
'must' => [
'term'=>['email.keyword'=>'test@think.com']
]
]
]
];
$result = Esdb::esGet($filter);
esGetById
根据ID查询
例如:
$id = "VdOa3GIBv0F8YUCs1PVZ";
$result = Esdb::esGetById($id);
esInsert
插入一条数据
例如:
$id = null;
$data = [
"id" => "VdOa3GIBv0F8YUCs1PVZ"
"content" => "test",
];
$result = Esdb::esInsert($data, $id);
esInsertAll
批量插入数据
例如:
$data_list = [
[
"id" => "VdOa3GIBv0F8YUCs1PVZ",
"content" => "test",
],
[
"id" => "VdOa3GIBv0F8YUCs1PVX",
"content" => "test",
]
];
$result = Esdb::esInsertAll($data_list);
esUpdateById
修改记录
例如:
$data = [
"content"=>"think"
];
$id = 'VdOa3GIBv0F8YUCs1PVZ';
$result = Esdb::esUpdateById($data, $id);
esDeleteById
删除一条记录
例如:
$id = 'VNOa3GIBv0F8YUCs1PVZ';
$result = Esdb::esDeleteById($id);
esDeleteByIds
批量删除
例如:
$ids = ['gNPW3GIBv0F8YUCsbPUZ',"VdOa3GIBv0F8YUCs1PVX"];
$result = Esdb::esDeleteByIds($id);