elasticsearch7.x和6.x版本分别在php中的变更细节

创建索引

es6

    // 生成房源信息索引
    public function esinit() {
   
        // 得到es客户端对象
        $client = ClientBuilder::create()->setHosts(config('es.host'))->build();
        // 创建索引
        $params = [
            // 生成索引的名称
            'index' => 'fang',
            // 类型 body
            'body' => [
                'settings' => [
                    // 分区数
                    'number_of_shards' => 5,
                    // 副本数
                    'number_of_replicas' => 1
                ],
                'mappings' => [
                    '_doc' => [
                        '_source' => [
                            'enabled' => true
                        ],
                        // 字段  类似表字段,设置类型
                        'properties' => [
                            'fang_name' => [
                                // 相当于数据查询是的 = 张三你好,必须找到张三你好
                                'type' => 'keyword'
                            ],
                            'fang_desn' => [
                                'type' => 'text',
                                // 中文分词  张三你好   张三  你好 张三你好
                                'analyzer' => 'ik_max_word',
                                'search_analyzer' => 'ik_max_word'
                            ]
                        ]
                    ]
                ]
            ]
        ];
        // 创建索引
        $response = $client->indices()->create($params);

        dump($response);
    }

es7

    // 生成房源信息索引
    public function esinit()
    {
   
        // 得到es客户端对象
        $client = ClientBuilder::create()->setHosts(config('es.host'))->build();
        // 创建索引
        $params = [
            // 生成索引的名称
            'index' => 'fang',
            // 类型 body
            'body' => [
                'settings' 

你可能感兴趣的:(elasticsearch7.x和6.x版本分别在php中的变更细节)