简体   繁体   English

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

[英]Need help connecting elasticsearch server and laravel localhost

I am trying to connect elasticsearch server to work on my localhost (real-estate-laravel.test).我正在尝试连接 elasticsearch 服务器以在我的本地主机(real-estate-laravel.test)上工作。 I downloaded and activated elasticsearch and have elastichsearch server running on http://localhost:9200/ , like this我下载并激活了 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"
}

And I added in my composer.json我添加了我的 composer.json

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

and entered composer update.并输入作曲家更新。 I am now confused on how to connect elasticsearch server with my localhost, so when I make some search queries in my controller they will search through elasticsearch.我现在对如何将 elasticsearch 服务器与我的本地主机连接感到困惑,所以当我在我的控制器中进行一些搜索查询时,他们将通过 elasticsearch 进行搜索。 Any help is appreciated.任何帮助表示赞赏。 Here is my controller.这是我的控制器。

CategoryController.php类别控制器.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()) 
        {
        }
    }
} 

In this if(Auth::check()) will go certain queries.在此 if(Auth::check()) 将进行某些查询。 Also when I dump $client I get this另外当我转储 $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: []
}

You might want to use cviebrock/laravel-elasticsearch package instead.您可能想改用cviebrock/laravel-elasticsearch包。

It allows you to setup your host information at .env file easily and use ClientBuilder as your current code.它允许您轻松地在.env文件中设置您的主机信息,并使用 ClientBuilder 作为您当前的代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM