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



我正在尝试使用laravel的ElasticSearch。以下是我到目前为止的配置:-

config/elastiquent.php

return array(
'config' => [
'hosts'     => ['localhost:9200'],
'retries'   => 1,
],
'default_index' => 'contents',
);

app/Content.php

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",
],
);
}

路由/web.php

Route::get('/', function () {
AppContent::createIndex($shards = null, $replicas = null);
AppContent::putMapping($ignoreConflicts = true);
AppContent::addAllToIndex();
return view('contents.index', [
'contents' => AppContent::all(),
]);
});
Route::get('/search', function() {
return AppContent::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();
});
}

我的应用程序正在位于:http://localhost:3024的docker容器上运行我的弹性搜索也在位于:的docker集装箱上运行

docker run --rm -d -e "discovery.type=single-node" -e "bootstrap.memory_lock=true" -p 9200:9200 elasticsearch:6.8.1

我可以使用cURL(并在浏览器中(访问它:-

curl -X GET 'http://localhost:9200'
{
"name" : "irt6ohl",
"cluster_name" : "docker-cluster",
"cluster_uuid" : "jtqcAMyJTRunrxobr6zE_g",
"version" : {
"number" : "6.8.1",
"build_flavor" : "default",
"build_type" : "docker",
"build_hash" : "1fad4e1",
"build_date" : "2019-06-18T13:16:52.517138Z",
"build_snapshot" : false,
"lucene_version" : "7.7.0",
"minimum_wire_compatibility_version" : "5.6.0",
"minimum_index_compatibility_version" : "5.0.0"
},
"tagline" : "You Know, for Search"
}

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

AppContent::createIndex($shards = null, $replicas = null);
AppContent::putMapping($ignoreConflicts = true);
AppContent::addAllToIndex();

这些设置ElasticSearch设置的基本设置

我在谷歌上搜索过,其他人也有类似的问题,但我找不到最终的解决方案。你能照亮它吗?

问题是每个docker几乎就像一个孤立的环境。

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

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

阅读:Docker Network Connect

最新更新