Generating Bridge Classes
To get started, create a bridge with the artisan make:bridge command. Bridges usually live in the App\Bridges directory. however, this can be changed through elasticbridge.namespace config.
php artisan make:bridge HotelRoomNaming Conventions
Bridges generated by the make:bridge command will be placed in the app/Bridges directory. Here's a basic bridge class and some key conventions:
<?php
namespace App\Bridges;
use Lacasera\ElasticBridge\ElasticBridge;
class HotelRoom extends ElasticBridge
{
}2
3
4
5
6
7
8
9
10
Index Names
The example above is a bridge class for HotelRoom bridge. By convention, just like an eloquent model, the snake case, plural name of the class will be used as the index name unless another name is explicitly specified.
If your bridge's corresponding search index does not fit this convention, you may manually specify the index name by defining an index property on the model:
<?php
namespace App\Bridges;
use Lacasera\ElasticBridge\ElasticBridge;
class HotelRoom extends ElasticBridge
{
protected $index = 'hotel-rooms';
}2
3
4
5
6
7
8
9
10
Multiple Indexes
Time-series data is often spread across many indexes (logs-2025.02.01, logs-2025.02.02, …). You usually want to search across all of them but write to one concrete index. ElasticBridge resolves the read and write index separately.
$index is the index (or wildcard/comma pattern) to read from:
class Log extends ElasticBridge
{
protected $index = 'logs-*'; // searches every logs-* index
}2
3
4
Writing to a wildcard is rejected (it is ambiguous). Set the concrete write target with $writeIndex, or override getWriteIndex() for a dynamic (e.g. date-based) target:
class Log extends ElasticBridge
{
protected $index = 'logs-*';
public function getWriteIndex(): string
{
return 'logs-'.date('Y.m.d');
}
}2
3
4
5
6
7
8
9
Documents read from a wildcard write back to the concrete index they came from, so updating a hit found via logs-* targets its exact index automatically.
Per-call overrides
Override the read or write index for a single query with from() and into():
// search specific indexes for this query
Log::from('logs-2025.02.01,logs-2025.02.02')
->asBoolean()
->matchAll()
->get();
Log::from(['logs-2025.02.01', 'logs-2025.02.02'])->get();
// write to a specific index for this call
Log::into('logs-2025.02.02')->create(['message' => 'hello']);2
3
4
5
6
7
8
9
10