Skip to content

关于elasticsearch建立索引,返回值为空 #12

Open
@54554980

Description

@54554980

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

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

    go(function () use ($elasticsearch) {
        $bean = new \EasySwoole\ElasticSearch\RequestBean\Bulk();
        $bean->setIndex('log_web');
        //$bean->setType('log');
            $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();   
        var_dump(json_decode($response, true));

结果如下:
图片

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions