需要帮助连接 elasticsearch 服务器和 laravel localhost



我正在尝试连接elasticsearch服务器以在我的本地主机(real-estate-laravel.test(上工作。我下载并激活了弹性搜索,并在 http://localhost:9200/上运行了弹性搜索服务器,像这样

{
"name" : "DESKTOP-F9QAVC4",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "5br4u4tTTR-xzg7FBeInPg",
"version" : {
"number" : "7.3.0",
"build_flavor" : "default",
"build_type" : "zip",
"build_hash" : "de777fa",
"build_date" : "2019-07-24T18:30:11.767338Z",
"build_snapshot" : false,
"lucene_version" : "8.1.0",
"minimum_wire_compatibility_version" : "6.8.0",
"minimum_index_compatibility_version" : "6.0.0-beta1"
},
"tagline" : "You Know, for Search"
}

我添加了我的作曲家.json

"require": {
"elasticsearch/elasticsearch": "^7.0"
}

并进入作曲家更新。我现在对如何将 elasticsearch 服务器与我的本地主机连接感到困惑,所以当我在我的控制器中进行一些搜索查询时,他们会通过 elasticsearch 进行搜索。任何帮助,不胜感激。这是我的控制器。

类别控制器.php

<?php
namespace AppHttpControllers;
use AppUser;
use AppCategory;
use AppProperty;
use IlluminateHttpRequest;
use AppHttpControllersController;
use IlluminateSupportFacadesAuth;
use IlluminateSupportFacadesCookie;
use ElasticsearchClientBuilder;
class CategoryController extends Controller
{
public function search(Category $category, Property $property, User $user)
{
$client = ClientBuilder::create()->build();
//dd($client);
if(Auth::check()) 
{
}
}
} 

在此 if(Auth::check((( 中将进行某些查询。同样当我转储$client我得到这个

Client {#351 ▼
+transport: Transport {#349 ▶}
#params: null
#indices: IndicesNamespace {#352 ▶}
#cluster: ClusterNamespace {#353 ▶}
#nodes: NodesNamespace {#354 ▶}
#snapshot: SnapshotNamespace {#355 ▶}
#cat: CatNamespace {#356 ▶}
#ingest: IngestNamespace {#357 ▶}
#tasks: TasksNamespace {#358 ▶}
#remote: RemoteNamespace {#359 ▶}
#endpoints: Closure($class) {#350 ▶}
#registeredNamespaces: []
}

你可能想改用cviebrock/laravel-elasticsearch包。

它允许您轻松地在.env文件中设置主机信息,并使用客户端构建器作为当前代码。

最新更新