hualaoshuan / swoft2-es
extension for Swoft2-ElasticSearch
v1.0.0
2020-04-27 02:11 UTC
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-02-27 14:04:26 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'; } }