tp5er / think-elasticsearch
An easy way to use the official PHP ElasticSearch client in your thinkphp applications.
Installs: 1 914
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Requires (Dev)
- elasticsearch/elasticsearch: ^7.11
- monolog/monolog: ^2.3
- topthink/framework: ^6.0
This package is auto-updated.
Last update: 2024-10-20 07:17:05 UTC
README
composer require tp5er/think-elasticsearch
基本配置
ELASTICSEARCH_HOST=localhost ELASTICSEARCH_PORT=9200 ELASTICSEARCH_SCHEME=http ELASTICSEARCH_USER= ELASTICSEARCH_PASS=
常规使用
$data = [ 'body' => [ 'testField' => 'abc' ], 'index' => 'my_index', 'type' => 'my_type', 'id' => 'my_id', ];
$client = ClientBuilder::create()->build(); $return = $client->index($data);
您现在可以简单地替换最后两行:
$return = \tp5er\think\elasticsearch\Elasticsearch::index($data);
这将在默认连接上运行命令。 你可以运行一个命令
任何连接(参见 defaultConnection
设置和 connections
数组
配置文件)。
$return = \tp5er\think\elasticsearch\Elasticsearch::connection('connectionName')->index($data);