Hola comunidad deseo usar la extensión yii2-elasticsearch y cuando realizo cualquier búsqueda me devuelve el siguiente error (he probado con los servidores web ampps y xamp,sin lograr corregirlo).El error está relacionado con la configuración del servidor pero no sé cómo corregirlo ,sin más acá les dejo el error que me lanza.
Por favor, agradezco la ayuda que me puedan prestar, nunca he utilizado esta extensión y según he estado indagando es la más completa para la realización de búsquedas.
Este error me lo da utilizando AMPPS:
Elasticsearch Database Exception – yii\elasticsearch\Exception
Elasticsearch request failed with code 403.
Error Info: Array
(
[requestMethod] => GET
[requestUrl] => http://127.0.0.1/basic/web:9200/_all/_search?queryParts%5Bsize%5D=10&queryParts%5Bquery%5D%5Bmatch%5D%5Bname%5D=a
[requestBody] => {"size":10,"query":{"match":{"name":"a"}}}
[responseCode] => 403
[responseHeaders] => Array
(
[date] => Wed, 19 Apr 2017 00:01:53 GMT
[server] => Apache/2.4.23 (Win32) OpenSSL/1.0.2h PHP/7.0.10 mod_wsgi/4.4.21 Python/3.5.2
[content-length] => 236
[content-type] => text/html; charset=iso-8859-1
)
[responseBody] =>
Forbidden
You don't have permission to access /basic/web:9200/_all/_search
on this server.
Este otro me lo muestra al utilizar XAMPP
Elasticsearch Database Exception – yii\elasticsearch\Exception
Elasticsearch request failed with code 403.
Error Info: Array
(
[requestMethod] => GET
[requestUrl] => http://127.0.0.1/basic/web:9200/_all/_search?queryParts%5Bsize%5D=10&queryParts%5Bquery%5D%5Bmatch%5D%5Bname%5D=a
[requestBody] => {"size":10,"query":{"match":{"name":"a"}}}
[responseCode] => 403
[responseHeaders] => Array
(
[date] => Wed, 19 Apr 2017 00:08:48 GMT
[server] => Apache/2.4.23 (Win32) OpenSSL/1.0.2h PHP/5.6.24
[vary] => accept-language,accept-charset
[accept-ranges] => bytes
[transfer-encoding] => chunked
[content-type] => text/html; charset=utf-8
[content-language] => en
)
[responseBody] =>
Access forbidden!
Acá les dejo los modelos y controlador que estoy utilizando
namespace app\controllers;
use app\models\Elastic;
use Yii;
use yii\web\Controller;
use yii\elasticsearch\Query;
use app\models\Search;
class ElasticController extends Controller
{
public function actionSearch()
{
$elastic = new Search();
$result = $elastic->Searches('');
$query = Yii::$app->request->queryParams;
var_dump($result->getModels());
// return $this->render('search', [
// 'searchModel' => $elastic,
// 'dataProvider' => $result,
// 'query' => $query['search'],
// ]);
}
<?php
namespace app\models;
use Yii;
class Elastic extends \yii\elasticsearch\ActiveRecord
{
public function attributes()
{
return['name', 'email'];
}
}
<?php
namespace app\models;
use app\models\Elastic;
use yii\base\Model;
//use yii\elasticsearch\ActiveDataProvider;
use yii\elasticsearch\Query;
use yii\elasticsearch\QueryBuilder;
class Search extends Elastic
{
public function Searches($value)
{
//die(print_r($value['search']));
//$search = $value['search'];
$query = new Query();
$db = Elastic::getDb();
$queryBuilder = new QueryBuilder($db);
$match = ['match'=>['name' => 'a']];
$query->query = $match;
$build = $queryBuilder->build($query);
$re = $query->search($db,$build);
$dataProvider = new \yii\elasticsearch\ActiveDataProvider([
"query" => $query,
"pagination" => ["pageSize" => 10]
]);
return $dataProvider;
}
}