yiisoft / yii2-elasticsearch

Yii 2 Elasticsearch extension
http://www.yiiframework.com
BSD 3-Clause "New" or "Revised" License
427 stars 253 forks source link

error when connect with Aliyun Elasticsearch 5.3 Service #192

Closed purevirtual closed 6 years ago

purevirtual commented 6 years ago

I use yii2-elasticsearch 2.1 cause I want to connect with Aliyun-es-service[version 5.3] But If failed when start to connect...

What steps will reproduce the problem?

I'm using yii2-elasticsearch 2.1, and this is my component configuration. 'elasticsearch' => [ 'class' => 'yii\elasticsearch\Connection', 'nodes' => [ // configure more hosts if you have a cluster [ 'http_address' => '.elasticsearch.aliyuncs.com:9200', ], ], 'auth' => ['username' => '', 'password' => '**'], ],

Producing following error 2018-08-13 11:49:38 [-][-][-][error][yii\elasticsearch\Exception] yii\elasticsearch\Exception: Elasticsearch request failed: 7 - Failed connect to 192.168.7.211:9200; Connection t imed out in /home/yangchao/project1/vendor/yiisoft/yii2-elasticsearch/Connection.php:504 Stack trace:

0 /home/yangchao/project1/vendor/yiisoft/yii2-elasticsearch/Connection.php(303): yii\elasticsearch\Connection->httpRequest('GET', 'http://192.168....', NULL, false)

1 /home/yangchao/project1/vendor/yiisoft/yii2-elasticsearch/Command.php(156): yii\elasticsearch\Connection->get(Array, Array)

2 /home/yangchao/project1/vendor/yiisoft/yii2-elasticsearch/ActiveRecord.php(149): yii\elasticsearch\Command->get('test-1', 'default', 1, Array)

3 /home/yangchao/project1/console/controllers/UpTestController.php(36): yii\elasticsearch\ActiveRecord::get(1)

4 [internal function]: console\controllers\UpTestController->actionEs()

5 /home/yangchao/project1/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)

6 /home/yangchao/project1/vendor/yiisoft/yii2/base/Controller.php(157): yii\base\InlineAction->runWithParams(Array)

7 /home/yangchao/project1/vendor/yiisoft/yii2/console/Controller.php(148): yii\base\Controller->runAction('es', Array)

8 /home/yangchao/project1/vendor/yiisoft/yii2/base/Module.php(528): yii\console\Controller->runAction('es', Array)

9 /home/yangchao/project1/vendor/yiisoft/yii2/console/Application.php(180): yii\base\Module->runAction('up-test/es', Array)

10 /home/yangchao/project1/vendor/yiisoft/yii2/console/Application.php(147): yii\console\Application->runAction('up-test/es', Array)

11 /home/yangchao/project1/vendor/yiisoft/yii2/base/Application.php(386): yii\console\Application->handleRequest(Object(yii\console\Request))

12 /home/yangchao/project1/yii(27): yii\base\Application->run()

13 {main}

Additional Information: Array ( [requestMethod] => GET [requestUrl] => http://192.168.7.211:9200/test-1/default/1 [requestBody] => [responseHeaders] => Array ( )

[responseBody] =>

)

What's expected?

It should be connect. but as per connection.php. It is simply ignoring nodes where http:publish_address key is not available in the response.

What do you get instead?

mentioned above

Additional info

Q A
Yii version 2.0.15.1
PHP version 7.1.13
Operating system CentOS Linux release 7.4.1708 (Core)

What I know and suggest

1 Why? Aliyun (a china compute cloud service provider like AWS) has SLB and access controller after its main node address [.elasticsearch.aliyuncs.com], so I should and just need to directly use the host rather than node address 2 How? So far, I just add one line code in Connection.php after "$node['http_address'] = $node['http']['publish_address'];" "$node['http_address'] = $host;", and it works so, I suggest, maybe, could you add a member called "$forceUseHost" in Connection.php?

purevirtual commented 6 years ago

Find the solution after reading the source code carefully... https://github.com/yiisoft/yii2-elasticsearch/pull/193

NingerJohn commented 1 year ago

@purevirtual curious to ask, how did you solved this problem?

purevirtual commented 9 months ago

@purevirtual curious to ask, how did you solved this problem?

see the comments above, I submit a commit next