定制 jeffleyd/esquery 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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

统计信息

  • 总下载量: 22
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-03-17

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固