PHP code example of esmp / elastic

1. Go to this page and download the library: Download esmp/elastic library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

esmp / elastic example snippets


php webman  esmp-elastic:index "app\Model\Test" //创建索引
php webman  esmp-elastic:flush "app\Model\Test" //清空索引及文档

        

namespace app\controller;

use app\model\Test;
use Es\Elasticsearch\ElasticSearchOperations;
use support\Request;

class TestController
{
    /**
     * @param Request $request
     * @return array
     */
    public function search(Request $request): array
    {
      $client = new ElasticSearchOperations();
        $client = $client->getClient();
        $res = $client->search([
            'index' => 'test', //索引名称
            'body' => [
                'query' => [
                    'match' => [
                        'name' => 'ec' //搜索字段
                    ]
                ]
            ]
        ]);

        dd($res->getBody()->getContents());
    }
}