elasticsearch,Laravel,elasticsearch" /> elasticsearch,Laravel,elasticsearch" />

在集群中找不到活动节点,Laravel,docker

在集群中找不到活动节点,Laravel,docker,laravel,elasticsearch,Laravel,elasticsearch,我正在用laravel试验ElasticSearch。以下是我目前的配置:- config/elasticquent.php return array( 'config' => [ 'hosts' => ['localhost:9200'], 'retries' => 1, ], 'default_index' => 'contents', ); class Content extends Model { use Elasticq

我正在用laravel试验ElasticSearch。以下是我目前的配置:-

config/elasticquent.php

return array(

 'config' => [
    'hosts'     => ['localhost:9200'],
    'retries'   => 1,
 ],

 'default_index' => 'contents',
);
class Content extends Model
{
 use ElasticquentTrait;

 protected $fillable = ['title', 'text', 'image'];

 protected $mappingProperties = array(
    'title' => [
        'type' => 'string',
        "analyzer" => "standard",
    ],
    'text' => [
        'type' => 'text',
        "analyzer" => "standard",
    ],
    'image' => [
        'type' => 'string',
        "analyzer" => "standard",
    ],
 );
}
Route::get('/', function () {
 App\Content::createIndex($shards = null, $replicas = null);
 App\Content::putMapping($ignoreConflicts = true);
 App\Content::addAllToIndex();

 return view('contents.index', [
    'contents' => App\Content::all(),
 ]);
});

Route::get('/search', function() {
 return App\Content::searchByQuery(['match' => ['title' => 'Adipisci']]);
});
app/Content.php

return array(

 'config' => [
    'hosts'     => ['localhost:9200'],
    'retries'   => 1,
 ],

 'default_index' => 'contents',
);
class Content extends Model
{
 use ElasticquentTrait;

 protected $fillable = ['title', 'text', 'image'];

 protected $mappingProperties = array(
    'title' => [
        'type' => 'string',
        "analyzer" => "standard",
    ],
    'text' => [
        'type' => 'text',
        "analyzer" => "standard",
    ],
    'image' => [
        'type' => 'string',
        "analyzer" => "standard",
    ],
 );
}
Route::get('/', function () {
 App\Content::createIndex($shards = null, $replicas = null);
 App\Content::putMapping($ignoreConflicts = true);
 App\Content::addAllToIndex();

 return view('contents.index', [
    'contents' => App\Content::all(),
 ]);
});

Route::get('/search', function() {
 return App\Content::searchByQuery(['match' => ['title' => 'Adipisci']]);
});
路由/web.php

return array(

 'config' => [
    'hosts'     => ['localhost:9200'],
    'retries'   => 1,
 ],

 'default_index' => 'contents',
);
class Content extends Model
{
 use ElasticquentTrait;

 protected $fillable = ['title', 'text', 'image'];

 protected $mappingProperties = array(
    'title' => [
        'type' => 'string',
        "analyzer" => "standard",
    ],
    'text' => [
        'type' => 'text',
        "analyzer" => "standard",
    ],
    'image' => [
        'type' => 'string',
        "analyzer" => "standard",
    ],
 );
}
Route::get('/', function () {
 App\Content::createIndex($shards = null, $replicas = null);
 App\Content::putMapping($ignoreConflicts = true);
 App\Content::addAllToIndex();

 return view('contents.index', [
    'contents' => App\Content::all(),
 ]);
});

Route::get('/search', function() {
 return App\Content::searchByQuery(['match' => ['title' => 'Adipisci']]);
});
composer.json

"require": {
 "elasticquent/elasticquent": "dev-master",
}

// database/migrations/2020_12_12_105155_create_contents_table.php
public function up()
{
 Schema::create('contents', function (Blueprint $table) {
    $table->bigIncrements('id');
    $table->string('title');
    $table->text('text');
    $table->string('image');
    $table->timestamps();
 });
}
我的应用程序正在docker容器上运行:
http://localhost:3024
My elasticsearch也在docker容器上运行,位于:

docker run --rm -d -e "discovery.type=single-node" -e "bootstrap.memory_lock=true" -p 9200:9200 elasticsearch:6.8.1
我可以使用cURL(并在浏览器中)访问它:-

我的数据库已经启动,迁移和种子很好。
routes/web.php
中的这三行似乎破坏了代码:-

App\Content::createIndex($shards = null, $replicas = null);
App\Content::putMapping($ignoreConflicts = true);
App\Content::addAllToIndex();
这些设置是ElasticSearch设置的基础


我在谷歌上搜索过,其他人也有类似的问题,但我无法找到一个明确的解决方案。你能照亮它吗?

问题是每个码头工人几乎都像一个孤立的环境

因此,您的应用程序(正在http://localhost:3024),正在尝试连接到同一容器上的localhost:9200。因此它会导致你所得到的错误

要解决此问题,需要通过网络连接两个容器

请阅读以下内容: