致命错误:班级' ..'未找到

时间:2016-03-23 10:56:00

标签: php elasticsearch symfony

我试图通过symfony中的PHP API使用Elasticsearch。 我通过Elasticsearch安装了composer

这是我的代码:

<?php

namespace AppBundle\ElasticsearchQuery;
use Elasticsearch\ClientBuilder;

class ElasticsearchQuery
{
private $Host = ['http://localhost:9200'];
private $client;
private $index = "homestead";

public function  __construct()
{
    $this->client = Elasticsearch\ClientBuilder::create()
        >setHosts($Host)->build();
}

public function execute($verb, $params)
{
    switch ($verb) {
    case "create":
        $response = $client->index($params);
        break;
    case "read":
        $response = $client->get($params);
        break;
    case "search":
        $response = $client->search($params);
        break;
    case "delete":
        $response = $client->delete($params);
        break;
    }
}
}

我得到的错误:

  

致命错误:Class&#39; AppBundle \ ElasticsearchQuery \ Elasticsearch \ ClientBuilder&#39;找不到

我不希望它在我的AppBundle中寻找Elasticsearch,我希望它在供应商中寻找它。 我该怎么做?

编辑:使用使用\ Elasticsearch \ ClientBuilder; Elasticsearch \ ClientBuilder :: create()没有区别

1 个答案:

答案 0 :(得分:3)

$this->client = Elasticsearch\ClientBuilder::create()

这应该是

$this->client = \Elasticsearch\ClientBuilder::create()

或(因为您已将该类导入您的命名空间)

$this->client = ClientBuilder::create()