hualaoshuan/swoft2-es

extension for Swoft2-ElasticSearch

v1.0.0 2020-04-27 02:11 UTC

This package is auto-updated.

Last update: 2022-05-27 07:35:16 UTC


README

composer require hualaoshuan/swoft2-es

使用方法

  1. 在对应的config/devconfig/pro目录下新建es.php配置文件
<?php

return [
    'host' => '192.168.60.169',
    'port' => 9200,
    'userName' => 'elastic',
    'password' => 'asdfasdf',
    'timeout' => 2,
];
  1. 在 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';
    }
}