Search code examples
elasticsearchyii2elasticsearch-plugin

How to use Yii2 elastic search


When i am trying to search data i have this error in console

PHP Notice 'yii\base\ErrorException' with message 'Use of undefined constant CURLOPT_USERAGENT - assumed 'CURLOPT_USERAGENT'' in /var/www/megamart/vendor/yiisoft/yii2-elasticsearch/Connection.php:320

I dont understand what is the problem Here my control and model Config file:

    'elasticsearch' => [
        'class' => 'yii\elasticsearch\Connection',
        'nodes' => [
            ['http_address' => '127.0.0.1:9200'],
        ],
    ],

Contorller file:

<?php 

namespace frontend\controllers;

use frontend\models\elastic\User;
use yii\web\Controller;
use Yii;
use yii\helpers\VarDumper;
class ElasticController extends Controller{

    public function actionTest(){
        if(Yii::$app->request->isAjax){
        $params = $_POST['q'];
        $query = User::find()->where(['username' => 'admin'])->one();
        VarDumper::dump($query,6,1);
        }
      }
   }

Model file:

<?php

namespace frontend\models\elastic;

class User extends \yii\elasticsearch\ActiveRecord
{
    public function attributes()
    {
        return ['id', 'username', 'address'];
    }

}

Solution

  • solved by installing this

    sudo apt-get install php5-curl