数据库 - Model 前置说明
官方开源项目 抓取代理IP

创建测试索引表

HTTP控制器:

namespace app\http;
use x\controller\Http;

class Index extends Http
{
    /**
     * @RequestMapping(route="/test1")
    */
    public function index() {
        $Elasticsearch = new \x\Elasticsearch();
        
        // 索引表配置
        $settings =  [
            'number_of_shards' => 5, // 分片值5
            'number_of_replicas' => 0 // 分布式拷贝数量为0
        ];
        // 字段信息
        $field = [
            'title' => [
                'type' => 'keyword',
            ],
            'lable' => [
                'type' => 'text',
            ],
            'score' => [
                'type' => 'integer',
            ],
        ];
        // 创建电影检索表
        $res = $Elasticsearch->table('film')->createTable($settings, $field);

        return $this->fetch(dd($res)); 
    }
}

插入测试数据

HTTP控制器:

namespace app\http;
use x\controller\Http;

class Index extends Http
{
    /**
     * @RequestMapping(route="/test2")
    */
    public function index() {
        $Elasticsearch = new \x\Elasticsearch();
        
        $data = [];
        $data[] = [
            'title' => '盗墓笔记',
            'lable' => '李易峰 唐嫣 杨洋 刘天佐 张智尧',
            'score' => 5
        ];
        $data[] = [
            'title' => '终极笔记',
            'lable' => '邹曦 马小刚 曾舜晞 肖宇梁',
            'score' => 9
        ];
        $data[] = [
            'title' => '盗墓笔记之云顶天宫',
            'lable' => '刘国辉 周煜壹 白澍 张博宇',
            'score' => 3
        ];
        // 批量插入测试数据
        $res = $Elasticsearch->table('film')->insertAll($data);

        return $this->fetch(dd($res)); 
    }
}

查询演示

HTTP控制器:

namespace app\http;
use x\controller\Http;

class Index extends Http
{
    /**
     * @RequestMapping(route="/test3")
    */
    public function index() {
        $Elasticsearch = new \x\Elasticsearch();
        
        // 查询李易峰出演的电影
        $res = $Elasticsearch->table('film')->where('lable', '=', '李易峰')->order('score DESC')->select();

        return $this->fetch(dd($res)); 
    }
}

SW-X

企业级 - 高性能 PHP 框架

最后更新:2年前 . 作者-小黄牛

本篇目录