我已经设置了新的laravel v5.3项目并安装弹性搜索驱动程序以通过composer实现弹性搜索。但是当我重新加载我的页面然后我总是收到这个页面不起作用,即使我的系统上运行的弹性搜索也是我编码的完整代码。
composer.json
"require": {
"php": ">=5.6.4",
"elasticsearch/elasticsearch": "^6.0",
"laravel/framework": "5.3.*"
},
web.php
Route::get('/',array('uses' => 'ElasticSearch@addPeopleList'));
控制器
<?php
namespace App\Http\Controllers;
class ElasticSearch extends Controller
{
// elastic
protected $elastic;
//elastic cliend
protected $client;
public function __construct(Client $client)
{
$this->client = ClientBuilder::create()->build();
$config = [
'host' =>'localhost',
'port' =>9200,
'index' =>'people',
];
$this->elastic = new ElasticClient($config);
}
public function addPeopleList(){
echo "<pre>";
print_r($this->$elastic);
exit;
}
}
但是当我刷新页面然后这个页面不能正常工作我收到这条消息和页面没有加载一件事我想让你知道我没有对配置的app.php文件做任何修改。请通过电子邮件解决此问题。
答案 0 :(得分:1)
如果要使用某种配置实例化弹性客户端,则应使用方法#curvedarrow:after {
content: "";
position: absolute;
border: 0 solid transparent; // make sure NO border is displayed
// it also makes the size of the
// borders = 0 in order to be
// able to do that "pointy" effect at
// the end of the tail
border-top: 3px solid red; // make a border on the top of the box and
// make it 3 pixels thick. this will be the
// final size of the transition
border-radius: 20px 0 0 0; // round the top left corner of the box
// (the one you actually see) with a
// radius of 20 pixels. Since in goes from
// 0 pxiels to 3 during this transformation,
// it will smoothly do so. Resulting in
// a "pointy" effect for the tail. if you
// want a staring tail, just use the same
// border size for the whole border
//those are basicaly just placing the tail at the right place
top: -12px;
left: -9px;
width: 12px;
height: 12px;
// rotate the tail 45 deg to the right.
// since each browser my act differently to `transform: rotate(45deg)`
// the code here just makes sure each browser uses it's own rotation
-webkit-transform: rotate(45deg);
-moz-transform: rotate(45deg);
-ms-transform: rotate(45deg);
-o-transform: rotate(45deg);
}
。
在你的情况下它应该是
ClientBuilder::fromConfig(array $config)
正如您所注意到的,上面的主机必须作为数组提供。
此外,我不确定您使用的Elasticsearch客户端是否具有<?php
$client = ClientBuilder::fromConfig([
'hosts' => [ 'localhost:9200' ]
]);
类。
此外,如果您从控制器提供的实际代码包含错误。您应该调用类属性:ElasticClient
(在属性名称附近没有print_r($this->client)
)。
最终你的控制器应该是这样的:
$
要向索引添加文档您需要根据官方文档
调用此命令<?php
namespace App\Http\Controllers;
use Elasticsearch\ClientBuilder;
class ElasticSearch extends Controller
{
/**
* @var \Elasticsearch\Client
*/
protected $client;
public function __construct()
{
$this->client = ClientBuilder::fromConfig([
'hosts' => [
'localhost:9200',
],
]);
}
public function addPeopleList(){
echo "<pre>";
print_r($this->client);
exit;
}
}
官方文档可在https://github.com/elastic/elasticsearch-php
找到P.S。对不起我的英语不好。它远非完美。