'how to connect elasticsearch cloud to Laravel?
I recently have a cloud version of elastic search, but I don't know to connect to it.
I install laravel/scout and jeroen-g/explorer driver for elastic cloud,
In my explorer config I have this:
config/explorer.php
<?php
declare(strict_types=1);
return [
'connection' => [
'host' => env('ELASTICSEARCH_HOST', 'localhost'),
'port' => env('ELASTICSEARCH_PORT', '9200'),
'scheme' => env('ELASTICSEARCH_SCHEME', 'http'),
],
/**
* An index may be defined on an Eloquent model or inline below. A more in depth explanation
* of the mapping possibilities can be found in the documentation of Explorer's repository.
*/
'indexes' => [
\App\Models\Post::class
],
/**
* You may opt to keep the old indices after the alias is pointed to a new index.
* A model is only using index aliases if it implements the Aliased interface.
*/
'prune_old_aliases' => true,
];
config/scout.php
<?php
return [
'driver' => env('SCOUT_DRIVER', 'algolia'),
'prefix' => env('SCOUT_PREFIX', ''),
'queue' => env('SCOUT_QUEUE', false),
'after_commit' => false,
'chunk' => [
'searchable' => 500,
'unsearchable' => 500,
],
'soft_delete' => false,
'identify' => env('SCOUT_IDENTIFY', false),
'algolia' => [
'id' => env('ALGOLIA_APP_ID', ''),
'secret' => env('ALGOLIA_SECRET', ''),
],
'meilisearch' => [
'host' => env('MEILISEARCH_HOST', 'http://localhost:7700'),
'key' => env('MEILISEARCH_KEY', null),
]
];
In my .env file I have this:
SCOUT_DRIVER=elastic
ELASTICSEARCH_HOST=https://myproject.ent.us-central1.gcp.cloud.es.io
ELASTICSEARCH_PORT=9243
ELASTICSEARCH_SCHEME=https
ELASTICSEARCH_USER=elastic
ELASTICSEARCH_PASS=WCFtnGU5vKFiPolMLpRlITBW //modified for security reasons
Then I ran this command:
php artisan scout:import "App\Models\Post"
and got this error:
Elasticsearch\Common\Exceptions\NoNodesAvailableException
No alive nodes found in your cluster
Maybe I need to change the port, or the host, I don't know, I know this is a configuration for a especific cloud tool, but I don't know how to make it work
Also in the cloud version I created I new engine and they provided an example:
curl -X POST 'https://myproject.ent.us-central1.gcp.cloud.es.io/api/as/v1/engines/myproject-search/documents' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer private-jkjkjkjkjkjkjk' \
-d '[
{
"id": "park_rocky-mountain",
"title": "Rocky Mountain",
"description": "Bisected north to south by the Continental Divide, this portion of the Rockies has ecosystems varying from over 150 riparian lakes to montane and subalpine forests to treeless alpine tundra. Wildlife including mule deer, bighorn sheep, black bears, and cougars inhabit its igneous mountains and glacial valleys. Longs Peak, a classic Colorado fourteener, and the scenic Bear Lake are popular destinations, as well as the historic Trail Ridge Road, which reaches an elevation of more than 12,000 feet (3,700 m).",
"nps_link": "https://www.nps.gov/romo/index.htm",
"states": [
"Colorado"
],
"visitors": 4517585,
"world_heritage_site": false,
"location": "40.4,-105.58",
"acres": 265795.2,
"square_km": 1075.6,
"date_established": "1915-01-26T06:00:00Z"
},
{
"id": "park_saguaro",
"title": "Saguaro",
"description": "Split into the separate Rincon Mountain and Tucson Mountain districts, this park is evidence that the dry Sonoran Desert is still home to a great variety of life spanning six biotic communities. Beyond the namesake giant saguaro cacti, there are barrel cacti, chollas, and prickly pears, as well as lesser long-nosed bats, spotted owls, and javelinas.",
"nps_link": "https://www.nps.gov/sagu/index.htm",
"states": [
"Arizona"
],
"visitors": 820426,
"world_heritage_site": false,
"location": "32.25,-110.5",
"acres": 91715.72,
"square_km": 371.2,
"date_established": "1994-10-14T05:00:00Z"
}
]'
# Returns
# [
# {
# "id": "park_rocky-mountain",
# "errors": []
# },
# {
# "id": "park_saguaro",
# "errors": []
# }
# ]
Then in the host configuration I change this
ELASTICSEARCH_HOST=https://fullremotejobs.ent.us-central1.gcp.cloud.es.io
to this:
ELASTICSEARCH_HOST=https://myproject.ent.us-central1.gcp.cloud.es.io/api/as/v1/engines/myproject-search/documents
But still not working, the same error, what can I do? thanks
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
