AWS elasticsearch

Defined in common/config/main.php:
‘elasticsearch’ => [
‘class’ => ‘yii\elasticsearch\Connection’,
‘‘defaultProtocol’ => ‘https’,
‘nodes’ => [
‘http_address’ => ‘’,
‘auth’ = [‘username’ => ‘xxx’, ‘password’ => xxx’],

The elastic search model:
class EsTest extends ActiveRecord {

public static function index() {
    return 'xxxxx'; 

public function attributes() {
    return [


When run with curl via command line with the same credential, i have no problem accessing the elasticsearch table.
However when trying to access as elastic search model, I get 401 unauthorized error. What could be the problem?

Hi CluWong,

It looks like the action in your controller added in the filters!. Check the filters in your controller

I’ve not used any filters yet…

The code in controller is simply:
public function actionTest() {
$model = EsTest::find()->all();
return $this->render(‘test’);

Found the fix. In elasticsearch config, add ‘autodetectCluster’ => false.