easy-swoole / easyswoole

swoole,easyswoole,swoole framework
https://www.easyswoole.com/
Apache License 2.0
4.74k stars 511 forks source link

在单条和批量插入elasticsearch 时提示Specifying types in urls has been deprecated #484

Closed 54554980 closed 3 years ago

54554980 commented 3 years ago

使用: easyswoole-3.4.4和elasticsearch 7.10.1,单条和批量插入时,提示错误如下: [2021-06-02 09:11:35][debug][notice]:[Specifying types in urls has been deprecated at file:/easyswoole/vendor/easyswoole/elasticsearch/src/Endpoints/Bulk.php line:22]。

部分源代码: $config = new \EasySwoole\ElasticSearch\Config([ 'host' => 'es01', 'port' => 9200, 'username' => 'elastic', 'password' => '*****', 'scheme' => 'https' ]);

    $elasticsearch = new \EasySwoole\ElasticSearch\ElasticSearch($config);

    go(function () use ($elasticsearch, $body) {
        $bean = new \EasySwoole\ElasticSearch\RequestBean\Bulk();
        $bean->setIndex('log_web');
        $bean->setType('tms_lbs_receive');
        /*     $body = [];
             for ($i = 1; $i <= 5; $i++) {
                 $body[] = [
                     'create' => [
                         '_index' => 'my-index',
                         '_type' => 'my-type',
                         '_id' => $i * 1000
                     ]
                 ];
                 $body[] = [
                     'test-field' => 'test-data',
                 ];
             }*/
        $bean->setBody($body);
        $response = $elasticsearch->client()->bulk($bean)->getBody();
        $response = json_decode($response, true);
        var_dump($response);

可能原因: es6时,官方就提到了es7会删除type,并且es6时已经规定每一个index只能有一个type。在es7中使用默认的_doc作为type,官方说在8.x版本会彻底移除type。

kiss291323003 commented 3 years ago

好的,我们这边同步适配

kiss291323003 commented 3 years ago

更新es客户端即可

54554980 commented 3 years ago
  $config = new \EasySwoole\ElasticSearch\Config([
        // 'scheme' => 'http',
        'host' => 'es01',
        'port' => 9200,
        'username' => 'elastic',
        'password' => 'xxx',
        'scheme' => 'https'
    ]);

    $elasticsearch = new \EasySwoole\ElasticSearch\ElasticSearch($config);

    go(function () use ($elasticsearch) {
        $bean = new \EasySwoole\ElasticSearch\RequestBean\Search();
        $bean->setIndex('tms_lbs_receive');
        // $bean->setType('_doc');
        $bean->setBody(['query' => ['matchAll' => []]]);
        $response = $elasticsearch->client()->search($bean)->getBody();
        var_dump(json_decode($response, true));
    });

结果如下: null 图片

54554980 commented 3 years ago

"name": "easyswoole/elasticsearch", "version": "1.0.3",

54554980 commented 3 years ago

更新es客户端即可 easyswoole/elasticsearch更新为1.0.3 但是输出结果为null

54554980 commented 3 years ago

再次测试代码如下:

go(function () use ($elasticsearch) { $bean = new \EasySwoole\ElasticSearch\RequestBean\Bulk(); $bean->setIndex('my_index'); //$bean->setType('my_type'); $body = []; for ($i = 1; $i <= 5; $i++) { $body[] = [ 'create' => [ '_index' => 'my-index', // '_type' => 'my-type', '_id' => $i * 1000 ] ]; $body[] = [ 'test-field' => 'test-data', ]; } $bean->setBody($body); $response = $elasticsearch->client()->bulk($bean)->getBody(); $response = json_decode($response, true); var_dump($response);

    });

测试结果如下: 如图所示,还是null 图片

54554980 commented 3 years ago

更新es客户端即可 再次增加setType测试: 会提示:[2021-06-18 16:10:14][trigger][notice]:[Specifying types in urls has been deprecated at file:/easyswoole/vendor/easyswoole/elasticsearch/src/Endpoints/Bulk.php line:22] 输出结果还是null;

代码如下: go(function () use ($elasticsearch) { $bean = new \EasySwoole\ElasticSearch\RequestBean\Bulk(); $bean->setIndex('my_index'); $bean->setType('my_type'); $body = []; for ($i = 1; $i <= 5; $i++) { $body[] = [ 'create' => [ '_index' => 'my-index', '_type' => 'my-type', '_id' => $i * 1000 ] ]; $body[] = [ 'test-field' => 'test-data', ]; } $bean->setBody($body); $response = $elasticsearch->client()->bulk($bean)->getBody(); $response = json_decode($response, true); var_dump($response);

    });