Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
54554980 opened this issue Jun 21, 2021 · 3 comments
Open

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

54554980 opened this issue Jun 21, 2021 · 3 comments

Comments

@54554980
Copy link

代码如下:
$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));

结果如下:
图片

@54554980
Copy link
Author

再次测试如下
代码如下:
$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();
$response = $elasticsearch->client()->get($bean)->getBody();*/
var_dump(json_decode($response, true));

提示错误如下:
[2021-06-21 09:33:38][trigger][notice]:[Specifying types in urls has been deprecated at file:/easyswoole/vendor/easyswoole/elasticsearch/src/Endpoints/Bulk.php line:22]
图片

@523013183
Copy link

523013183 commented Sep 9, 2021

Trying to access array offset on value of type null at file:vendor/jeremeamia/superclosure/src/SerializableClosure.php(210) : eval()'d code line:14
我也是返回null

elastic: 7.9.2
swoole version 4.4.26
php version 7.4.12
easy swoole 3.3.4

不加 x-pack 登录验证时,是正常的。

$config = new Config([
    'host' => '192.168.2.78',
    'port' => 9200,
    'username' => 'elastic',
    'password' => '123456'
]);
$elasticsearch = new ElasticSearch($config);

$bean = new \EasySwoole\ElasticSearch\RequestBean\Count();
$response = $elasticsearch->client()->count($bean)->getBody();
$response = json_decode($response, true);
var_dump($response['count']);

@523013183
Copy link

Trying to access array offset on value of type null at file:vendor/jeremeamia/superclosure/src/SerializableClosure.php(210) : eval()'d code line:14
我也是返回null

elastic: 7.9.2
swoole version 4.4.26
php version 7.4.12
easy swoole 3.3.4

不加 x-pack 登录验证时,是正常的。

$config = new Config([
    'host' => '192.168.2.78',
    'port' => 9200,
    'username' => 'elastic',
    'password' => '123456'
]);
$elasticsearch = new ElasticSearch($config);

$bean = new \EasySwoole\ElasticSearch\RequestBean\Count();
$response = $elasticsearch->client()->count($bean)->getBody();
$response = json_decode($response, true);
var_dump($response['count']);

知道了, es就开启了本机访问,开启全网访问就正常了。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants