logcomex/aws-elasticsearch-laravel 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

logcomex/aws-elasticsearch-laravel

Composer 安装命令:

composer require logcomex/aws-elasticsearch-laravel

包简介

AWS Elasticsearch Service for Laravel/Lumen

README 文档

README

AWS Elasticsearch Service for Laravel/Lumen

NOTE: This package only caters search, aggregation, and indexing transactions. Other than that, you can refer to elasticsearch's official documentation.

Installation

composer require elegisandi/aws-elasticsearch-laravel

Laravel/Lumen Integration

  • Add service provider to your config/app.php providers

    elegisandi\AWSElasticsearchService\ElasticSearchServiceProvider::class
    
  • Add facade to your config/app.php aliases

    'ElasticSearch' => elegisandi\AWSElasticsearchService\Facades\ElasticSearch::class
    
  • Set AWS credentials and Elasticsearch config in your .env file

      AWS_ACCESS_KEY_ID
      AWS_SECRET_ACCESS_KEY
      AWS_REGION
    
      ELASTICSEARCH_ENDPOINT
      ELASTICSEARCH_PORT
      ELASTICSEARCH_SHARDS
      ELASTICSEARCH_REPLICAS
      ELASTICSEARCH_DEFAULT_INDEX
      ELASTICSEARCH_DEFAULT_TYPE
      ELASTICSEARCH_DEFAULT_TIME_FILTER_FIELD
    

    When you are already using aws elasticsearch service, set

      AWS_ELASTICSEARCH_SERVICE=true
    

If you want to configure elasticsearch mappings, settings and/or default type and index, just run:

php artisan vendor:publish --provider=elegisandi\\AWSElasticsearchService\\ElasticSearchServiceProvider

For Lumen:

  • Register service provider to your bootstrap/app.php

    $app->register(elegisandi\AWSElasticsearchService\ElasticSearchServiceProvider::class);      
    

Basic Usage

Using Facade:

<?php
    
namespace App;

use ElasticSearch;

public function index() {
    extract(ElasticSearch::setSearchParams(request()));

    $clicks = [];
    $total = 0;

    if ($hits = ElasticSearch::search($query, $options, $date_range)) {
        $clicks = $hits['hits']['hits'];
        $total = $hits['hits']['total'];
    }
}

For Lumen:

<?php
        
namespace App;

public function index() {
    extract(app('elasticsearch')->setSearchParams(request()));

    $clicks = [];
    $total = 0;

    if ($hits = app('elasticsearch')->search($query, $options, $date_range)) {
        $clicks = $hits['hits']['hits'];
        $total = $hits['hits']['total'];
    }
}

Console Commands

  • Create Index (creates the default index)

    php artisan elasticsearch:create-index

    To reset existing index,

    php artisan elasticsearch:create-index --reset

  • Update Index Mapping (updates the default index mapping)

    php artisan elasticsearch:update-index-mapping

    Only supports new properties updates.

Available Methods

  • aggregations(array $aggs, array $query = [], array $options = [], $type, $index)

    $aggs : must follow the structure specified in elasticsearch docs.

    $query : see search method $query argument

    $options : see search method $options argument

    returns Array

  • search(array $query = [], array $options = [], array $range = [], $type, $index)

    $query : an array of key-value pair of any available properties

    $options : an array of key-value pair of the ff: from, size, sort

    $range : an array representation of range query.

    returns Array

  • count(array $query = [], array $range = [], $type, $index)

    a (syntactic sugar) method of search with zero hits result

    returns Int

  • setSearchParams(Request $request, array $defaults = [], $type)

    an optional and conventional approach of setting search params via query string

    $request : an instance of \Illuminate\Http\Request, query variables in used:

    • range, see getDateRange method
    • start, a valid date string
    • end, a valid date string
    • sort, a mapping property
    • order, value is either desc or asc
    • size, total results to return (max of 10000)

    $defaults : an array of key-value pair of the ff: sort, order, size

    returns Array

  • getDateRange($range, $format = null)

    $range : predefined date range values: today, yesterday, last-7-days, this-month, last-month, last-2-months, last-3-months

    $format must be a valid date format, default is null which will return a DateTime instance

    returns Array

  • setAggregationDailyDateRanges($start, $end, $format = null)

    $format must be a valid date format, default is null which will return a DateTime instance

    returns Array

  • defaultAggregationNames

    returns Array

  • defaultIndex

    returns String

  • defaultType

    returns String

  • defaultTimeFilterField

    returns String

  • setSearchQueryFilters(Collection $query, array $bool_clauses = [], $type = null)

    returns Array

  • setBoolQueryClause(Collection $query, array $properties, $context, $occur, callable $callback = null)

    returns Array

  • getMappingPropertiesByDataType(Collection $properties, $data_type)

    returns Array

  • getMappingProperties($type = null)

    returns Collection

  • indexDocument(array $body, $type = null, $index = null)

    returns Array

  • getDocument($id, $type, $index)

    returns Array

  • updateDocument(array $fields, $id, $type = null, $index = null)

    returns Array

  • deleteDocument($id, $type = null, $index = null)

    returns Array

  • getSettings($index = null)

    returns Array

  • updateSettings(array $settings, $index)

    returns Array

  • getMappings($index, $type)

    returns Array

  • updateMappings(array $properties, $type, $index)

    returns Array

  • createIndex(array $mappings, array $settings, $index)
  • getIndex($index = null)

    returns Boolean

  • deleteIndex($index)

    returns Array

NOTE: All methods of the elasticsearch client are now supported.

Limitations

  • Supported data types in search method are:

    • keyword
    • text
    • array
    • integer
    • boolean
    • ip

Contributing

Open an issue first to discuss potential changes/additions.

License

MIT

logcomex/aws-elasticsearch-laravel 适用场景与选型建议

logcomex/aws-elasticsearch-laravel 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2 次下载、GitHub Stars 达 1, 最近一次更新时间为 2021 年 03 月 31 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「elasticsearch」 「aws」 「laravel」 「elegisandi」 「aws-elasticsearch-laravel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 logcomex/aws-elasticsearch-laravel 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 logcomex/aws-elasticsearch-laravel 我们能提供哪些服务?
定制开发 / 二次开发

基于 logcomex/aws-elasticsearch-laravel 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-03-31