我正在尝试连接elasticsearch服务器以在我的本地主机(real-estate-laravel.test)上工作。我下载并激活了Elasticsearch,并在http://localhost:9200/上运行了Elastichsearch服务器,就像这样
{
"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"
}
然后我在composer.json中添加了
"require": {
"elasticsearch/elasticsearch": "^7.0"
}
并输入作曲家更新。现在,我对如何将Elasticsearch服务器与本地主机连接感到困惑,因此当我在控制器中进行一些搜索查询时,它们将通过Elasticsearch进行搜索。任何帮助表示赞赏。这是我的控制器。
CategoryController.php
<?php
namespace App\Http\Controllers;
use App\User;
use App\Category;
use App\Property;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Cookie;
use Elasticsearch\ClientBuilder;
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: []
}
答案 0 :(得分:1)
您可能想改用cviebrock/laravel-elasticsearch软件包。
它使您可以轻松地在.env
文件中设置主机信息,并将ClientBuilder用作当前代码。