hualaoshuan / swoft2-es
extension for Swoft2-ElasticSearch
Installs: 6
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 1
Open Issues: 0
pkg:composer/hualaoshuan/swoft2-es
Requires
- php: >=7.0
- ext-json: >=1.3.7
- guzzlehttp/ringphp: ~1.0
- swoft/framework: ^2.0
Suggests
- ext-curl: *
- monolog/monolog: Allows for client-level logging and tracing
This package is auto-updated.
Last update: 2025-09-27 15:08:57 UTC
README
composer require hualaoshuan/swoft2-es
使用方法
- 在对应的
config/dev
和config/pro
目录下新建es.php
配置文件
<?php return [ 'host' => '192.168.60.169', 'port' => 9200, 'userName' => 'elastic', 'password' => 'asdfasdf', 'timeout' => 2, ];
- 在 Controller 里调用
<?php namespace App\Http\Controller; use Hualaoshuan\Elasticsearch\Es; use Swoft\Http\Server\Annotation\Mapping\Controller; use Swoft\Http\Server\Annotation\Mapping\RequestMapping; use Swoft\Http\Server\Annotation\Mapping\RequestMethod; /** * Class testController * @Controller(prefix="/test") */ class TestController{ /** * @RequestMapping(route="/test",method={RequestMethod::GET}) */ public function test(){ $result = Es::getClient()->get([ 'id' => 1, 'index' => 'shop', 'type' => '_doc' ]); print_R($result); return 'OK'; } }