Use syntax similar to eloquent, using the elastic search service.
jeffleyd/esquery is a Laravel package for use syntax similar to eloquent, using the elastic search service..
It currently has 1 GitHub stars and 22 downloads on Packagist (latest version v1.1.6).
Install it with composer require jeffleyd/esquery.
Discover more Laravel packages by jeffleyd
or browse all Laravel packages to compare alternatives.
Last updated
This project is to be similar to the eloquent query, like this
facilitating searches in ElasticSearch's Lucene.
composer require jeffleyd/esquery
php artisan vendor:publish --tag="esquery-provider"
Access the config folder and change the settings of the esquery.php file.
$build = EsQuery::index('my_index');
$response = $build->createIndex([
'mappings' => [
'properties' => [
'parent_id' => [
'type' => 'long',
],
'created_at' => [
'type' => 'date',
'format' => 'yyyy-MM-dd HH:mm:ss||yyyy-MM-dd'
]
]
]
]);
public function up()
{
EsScheme::create('bosses', function (EsMapping $table) {
$table->integer('id');
$table->string('name');
$table->string('email');
$table->nested('json');
$table->timestamp('created_at');
$table->timestamp('updated_at');
// If you want to use a simple analyzer, you can add the following line.
$table->setDefaultAnalyzer();
// If you want to use a custom analyzer, you can use the following:
$table->mapping['settings'] = [
'analysis' => [
'default_analyze' => [
'type' => 'custom',
'tokenizer' => 'whitespace',
'char_filter' => [
'html_strip'
],
'filter' => [
'lowercase'
]
]
]
];
});
}
public function down()
{
EsScheme::dropIfExists('boss');
}
$build = EsQuery::index('my_index');
$response = $build->create([
'parent_id' => 1,
'created_at' => '2022-02-26 23:44:00',
]);
$build = EsQuery::index('my_index');
$response = $build->where('parent_id', 1)->first(); // Example 1
$response = $build->where('parent_id', '=', 1)->first(); // Example 2
$response = $build->where('parent_id', 1)->get(); // Example 3
$response = $build->where('created_at', '>=' '2022-02-26'))->get(); // Example 4
$build = EsQuery::index('my_index');
$response = $build->where('parent_id', 1)->sum('price', 'total_price')->get(); // Use get() for aggregations
$build = EsQuery::index('my_index');
$response = $build->where('parent_id', 1)->delete(); // Example 1 delete with conditions
$response = $build->delete(5); // Example 2 delete by ID
$build = EsQuery::index('my_index');
$response = $build->deleteIndex();
$build = EsQuery::index('my_index');
$response = $build->with('category', 'id', 'group_id')->get();
OR
$build = EsQuery::index('my_index');
$response = $build->with('category', 'id', 'group_id', function (QueryBuilder $query) {
return $query->where('is_active', 1);
})->with('boss', 'id', 'boss_id', function (QueryBuilder $query) {
return $query->where('is_active', 1);
})->get();
[x] Create
[x] Delete
[x] Update mapping
[x] Exists
[x] Skip
[x] Create
[x] Create Many
[x] Update
[x] Delete by ID
[x] Delete by Query
[x] FIRST (with/without conditions)
[x] GET (with/without conditions)
[x] PAGINATION (with/without conditions)
[x] AGGREGATION MAX / MIN / SUM / AVG / COUNT
[x] LIMIT
[x] GROUP BY
[x] GROUP BY DATE
[x] where
[x] whereIn
[x] whereExists
[x] whereNotExists
[x] whereMissing
[x] between
[x] orderBy
[x] with
[x] reset query after get/first/paginate
Site: https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html
Version: 8.1