yiisoft / yii2-elasticsearch

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

auth connection error #347

Closed NingerJohn closed 9 months ago

NingerJohn commented 9 months ago

What steps will reproduce the problem?

  1. config as following

    'elasticsearch' => [
            'class' => 'yii\elasticsearch\Connection',
            'nodes' => [
                [
                    'http_address' => 'xxxxhost:9200',
                    'protocol' => 'https',
                    'auth' => [
                        'username' => 'elastic',
                        'password' => 'xxxxxxx',
                    ],
                ],
            ],
            'dslVersion' => 7
        ],
  2. try to do searc using yii\elasticsearch\Query

    $query = (new \yii\elasticsearch\Query())
                ->from('whole_site_search')
                ->query(['match' => ['content' => $params['keyword']]])->search();
  3. then I got the error outut from app.log file

    
    Array
    (
    [requestMethod] => GET
    [requestUrl] => https://xxxx-host:9200/_nodes/_all/http
    [requestBody] =>
    [responseCode] => 401
    [responseHeaders] => Array
        (
            [date] => Fri, 29 Sep 2023 08:43:13 GMT
            [content-type] => application/json; charset=UTF-8
            [content-length] => 413
            [server] => nginx
            [www-authenticate] => Basic realm="security" charset="UTF-8"
        )
    
    [responseBody] => Array
        (
            [error] => Array
                (
                    [root_cause] => Array
                        (
                            [0] => Array
                                (
                                    [type] => security_exception
                                    [reason] => missing authentication credentials for REST request [/_nodes/_all/http]
                                    [header] => Array
                                        (
                                            [WWW-Authenticate] => Basic realm="security" charset="UTF-8"
                                        )
    
                                )
    
                        )
    
                    [type] => security_exception
                    [reason] => missing authentication credentials for REST request [/_nodes/_all/http]
                    [header] => Array
                        (
                            [WWW-Authenticate] => Basic realm="security" charset="UTF-8"
                        )
    
                )
    
            [status] => 401
        )
    )


### What's expected?
Successful connection and query working

### What do you get instead?
unable to connect to elasticsearch

### Additional info

| Q                | A
| ---------------- | ---
| Yii version       |  2.0.44 
| PHP version      | 7.4.3
| Operating system | Ubuntu 20.04 LTS
yuniorsk commented 9 months ago

Have you tried to set autodetectCluster to false in elasticsearch connection configuration?

NingerJohn commented 9 months ago

Have you tried to set autodetectCluster to false in elasticsearch connection configuration?

Thank you so much, it works, saved my day !