jeffleyd/esquery
Composer 安装命令:
composer require jeffleyd/esquery
包简介
Use syntax similar to eloquent, using the elastic search service.
关键字:
README 文档
README
This project is to be similar to the eloquent query, like this
facilitating searches in ElasticSearch's Lucene.
composer require jeffleyd/esquery
PUBLISH THE FILE CONFIG
php artisan vendor:publish --tag="esquery-provider"
Access the config folder and change the settings of the esquery.php file.
USAGE EXAMPLES
First create a mapping for your index
For more information about mapping types: https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-types.html
$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'
]
]
]
]);
If you want to add a new index, you can do it like this
Create a migration file and extend the EsScheme class
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');
}
Now you can create your first document
$build = EsQuery::index('my_index');
$response = $build->create([
'parent_id' => 1,
'created_at' => '2022-02-26 23:44:00',
]);
Find your document
$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
Performing an aggregation
$build = EsQuery::index('my_index');
$response = $build->where('parent_id', 1)->sum('price', 'total_price')->get(); // Use get() for aggregations
Delete your document
$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
Delete your index
$build = EsQuery::index('my_index');
$response = $build->deleteIndex();
How you can attach relation
$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();
INDEX
[x] Create
[x] Delete
[x] Update mapping
[x] Exists
[x] Skip
DOCUMENT
[x] Create
[x] Create Many
[x] Update
[x] Delete by ID
[x] Delete by Query
TYPE SEARCH
[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
CONDITIONS
[x] where
[x] whereIn
[x] whereExists
[x] whereNotExists
[x] whereMissing
[x] between
[x] orderBy
ADDITIONAL
[x] with
[x] reset query after get/first/paginate
ELASTIC SEARCH
Site: https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html
Version: 8.1
jeffleyd/esquery 适用场景与选型建议
jeffleyd/esquery 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 22 次下载、GitHub Stars 达 1, 最近一次更新时间为 2022 年 03 月 17 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「elastic search」 「elastic search eloquent」 「elastic search laravel」 「laravel elastic search」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 jeffleyd/esquery 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 jeffleyd/esquery 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 jeffleyd/esquery 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A Laravel package to retrieve data from Google Search Console
This package includes a script and fail2ban configuration that allows you to use fail2ban when utilizing AWS elastic load balancer (ELB) and an apache webserver.
Indexed Search Autocomplete - Extends the TYPO3 Core Extension Indexed_Search searchform with an autocomplete feature.
Elastic Driver for Laravel Scout
Abstraction Layer to index and search entities
Package for send emails with attachments via elastic email driver
统计信息
- 总下载量: 22
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 7
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-03-17