| Package Data | |
|---|---|
| Maintainer Username: | elegisandi |
| Maintainer Contact: | elegisandi@gmail.com (Elegi Sandi) |
| Package Create Date: | 2017-10-18 |
| Package Last Update: | 2020-02-05 |
| Language: | PHP |
| License: | MIT |
| Last Refreshed: | 2025-10-19 15:08:16 |
| Package Statistics | |
|---|---|
| Total Downloads: | 15,323 |
| Monthly Downloads: | 41 |
| Daily Downloads: | 0 |
| Total Stars: | 6 |
| Total Watchers: | 3 |
| Total Forks: | 8 |
| Total Open Issues: | 0 |
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.
composer require elegisandi/aws-elasticsearch-laravel
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);
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'];
}
}
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.
array $aggs, array $query = [], array $options = [], $type, $index)$aggs : must follow the structure specified in elasticsearch docs.
$query : see
searchmethod$queryargument
$options : see
searchmethod$optionsargument
returns
Array
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
array $query = [], array $range = [], $type, $index)a (syntactic sugar) method of search with zero hits result
returns
Int
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 methodstart, a valid date stringend, a valid date stringsort, a mapping propertyorder, 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
$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
nullwhich will return a DateTime instance
returns
Array
$start, $end, $format = null)$format must be a valid date format, default is
nullwhich will return a DateTime instance
returns
Array
returns
Array
returns
String
returns
String
returns
String
Collection $query, array $bool_clauses = [], $type = null)returns
Array
Collection $query, array $properties, $context, $occur, callable $callback = null)returns
Array
Collection $properties, $data_type)returns
Array
$type = null)returns
Collection
array $body, $type = null, $index = null)returns
Array
$id, $type, $index)returns
Array
array $fields, $id, $type = null, $index = null)returns
Array
$id, $type = null, $index = null)returns
Array
$index = null)returns
Array
array $settings, $index)returns
Array
$index, $type)returns
Array
array $properties, $type, $index)returns
Array
array $mappings, array $settings, $index)returns
Boolean
$index)returns
Array
Supported data types in search method are:
Open an issue first to discuss potential changes/additions.