2017 © Pedro Peláez
 

library aws-elasticsearch-laravel

AWS Elasticsearch Service for Laravel/Lumen

image

elegisandi/aws-elasticsearch-laravel

AWS Elasticsearch Service for Laravel/Lumen

  • Thursday, June 14, 2018
  • by elegisandi
  • Repository
  • 3 Watchers
  • 4 Stars
  • 487 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 11 Versions
  • 227 % Grown

The README.md

aws-elasticsearch-laravel

AWS Elasticsearch Service for Laravel/Lumen, (*1)

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

Installation

composer require elegisandi/aws-elasticsearch-laravel

Laravel/Lumen Integration

  • Add service provider to your config/app.php providers, (*3)

    elegisandi\AWSElasticsearchService\ElasticSearchServiceProvider::class, (*4)

  • Add facade to your config/app.php aliases, (*5)

    'ElasticSearch' => elegisandi\AWSElasticsearchService\Facades\ElasticSearch::class, (*6)

  • Set AWS credentials and Elasticsearch config in your .env file, (*7)

    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, (*8)

    AWS_ELASTICSEARCH_SERVICE=true

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

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

For Lumen:, (*10)

  • Register service provider to your bootstrap/app.php, (*11)

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

Basic Usage

Using Facade:, (*13)

<?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:, (*14)

<?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), (*15)

    php artisan elasticsearch:create-index, (*16)

    To reset existing index,, (*17)

    php artisan elasticsearch:create-index --reset, (*18)

  • Update Index Mapping (updates the default index mapping), (*19)

    php artisan elasticsearch:update-index-mapping, (*20)

    Only supports new properties updates., (*21)

Available Methods

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

    $aggs : must follow the structure specified in elasticsearch docs., (*22)

    $query : see search method $query argument, (*23)

    $options : see search method $options argument, (*24)

    returns Array, (*25)

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

    $query : an array of key-value pair of any available properties, (*26)

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

    $range : an array representation of range query., (*28)

    returns Array, (*29)

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

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

    returns Int, (*31)

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

    an optional and conventional approach of setting search params via query string, (*32)

    $request : an instance of \Illuminate\Http\Request, query variables in used:, (*33)

    • 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, (*34)

    returns Array, (*35)

  • getDateRange($range, $format = null)

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

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

    returns Array, (*38)

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

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

    returns Array, (*40)

  • defaultAggregationNames

    returns Array, (*41)

  • defaultIndex

    returns String, (*42)

  • defaultType

    returns String, (*43)

  • defaultTimeFilterField

    returns String, (*44)

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

    returns Array, (*45)

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

    returns Array, (*46)

  • getMappingPropertiesByDataType(Collection $properties, $data_type)

    returns Array, (*47)

  • getMappingProperties($type = null)

    returns Collection, (*48)

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

    returns Array, (*49)

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

    returns Array, (*50)

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

    returns Array, (*51)

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

    returns Array, (*52)

  • getSettings($index = null)

    returns Array, (*53)

  • updateSettings(array $settings, $index)

    returns Array, (*54)

  • getMappings($index, $type)

    returns Array, (*55)

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

    returns Array, (*56)

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

    returns Boolean, (*57)

  • deleteIndex($index)

    returns Array, (*58)

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

Limitations

  • Supported data types in search method are:, (*59)

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

Contributing

Open an issue first to discuss potential changes/additions., (*60)

License

MIT, (*61)

The Versions

14/06 2018

dev-master

9999999-dev https://github.com/elegisandi/aws-elasticsearch-laravel

AWS Elasticsearch Service for Laravel/Lumen

  Sources   Download

MIT

The Requires

 

by Elegi Sandi

laravel elasticsearch aws elegisandi aws-elasticsearch-laravel

14/06 2018

v1.4.4

1.4.4.0 https://github.com/elegisandi/aws-elasticsearch-laravel

AWS Elasticsearch Service for Laravel/Lumen

  Sources   Download

MIT

The Requires

 

by Elegi Sandi

laravel elasticsearch aws elegisandi aws-elasticsearch-laravel

23/04 2018

v1.4.3

1.4.3.0 https://github.com/elegisandi/aws-elasticsearch-laravel

AWS Elasticsearch Service for Laravel/Lumen

  Sources   Download

MIT

The Requires

 

by Elegi Sandi

laravel elasticsearch aws elegisandi aws-elasticsearch-laravel

19/04 2018

v1.4.2

1.4.2.0 https://github.com/elegisandi/aws-elasticsearch-laravel

AWS Elasticsearch Service for Laravel/Lumen

  Sources   Download

MIT

The Requires

 

by Elegi Sandi

laravel elasticsearch aws elegisandi aws-elasticsearch-laravel

03/04 2018

v1.4.1

1.4.1.0 https://github.com/elegisandi/aws-elasticsearch-laravel

AWS Elasticsearch Service for Laravel/Lumen

  Sources   Download

MIT

The Requires

 

by Elegi Sandi

laravel elasticsearch aws elegisandi aws-elasticsearch-laravel

02/04 2018

v1.4

1.4.0.0 https://github.com/elegisandi/aws-elasticsearch-laravel

AWS Elasticsearch Service for Laravel/Lumen

  Sources   Download

MIT

The Requires

 

by Elegi Sandi

laravel elasticsearch aws elegisandi aws-elasticsearch-laravel

26/03 2018

v1.3.1

1.3.1.0 https://github.com/elegisandi/aws-elasticsearch-laravel

AWS Elasticsearch Service for Laravel/Lumen

  Sources   Download

MIT

The Requires

 

by Elegi Sandi

laravel elasticsearch aws elegisandi aws-elasticsearch-laravel

14/03 2018

v1.3

1.3.0.0 https://github.com/elegisandi/aws-elasticsearch-laravel

AWS Elasticsearch Service for Laravel/Lumen

  Sources   Download

MIT

The Requires

 

by Elegi Sandi

laravel elasticsearch aws elegisandi aws-elasticsearch-laravel

13/03 2018

v1.2

1.2.0.0 https://github.com/elegisandi/aws-elasticsearch-laravel

AWS Elasticsearch Service for Laravel/Lumen

  Sources   Download

MIT

The Requires

 

by Elegi Sandi

laravel elasticsearch aws elegisandi aws-elasticsearch-laravel

12/03 2018

v1.1

1.1.0.0 https://github.com/elegisandi/aws-elasticsearch-laravel

AWS Elasticsearch Service for Laravel/Lumen

  Sources   Download

MIT

The Requires

 

by Elegi Sandi

laravel elasticsearch aws elegisandi aws-elasticsearch-laravel

04/12 2017

v1.0

1.0.0.0 https://github.com/elegisandi/aws-elasticsearch-laravel

AWS Elasticsearch Service for Laravel/Lumen

  Sources   Download

MIT

The Requires

 

by Elegi Sandi

laravel elasticsearch aws elegisandi aws-elasticsearch-laravel