Download the PHP package greensight/laravel-elastic-query without Composer
On this page you can find all versions of the php package greensight/laravel-elastic-query. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package laravel-elastic-query
Laravel Elastic Query
Deprecated, use https://github.com/ensi-platform/laravel-telemetry instead
Working with Elasticsearch in an Eloquent-like fashion.
Installation
You can install the package via composer:
composer require greensight/laravel-elastic-query
- Set
ELASTICSEARCH_HOSTS
in your.env
file.,
can be used as a delimeter.
Basic usage
Let's create and index class. It's someting like Eloquent model.
You should set a unique in document attribute name in $tiebreaker
. It is used as an additional sort in search_after
Now we can get some documents
Filtering
nested_field
must have nested
type.
Subqueries cannot use fields of main document only subdocument.
Sorting
Second attribute is a direction. It supports asc
and desc
values. Defaults to asc
.
Third attribute - sorting type. List of supporting types: min, max, avg, sum, median
. Defaults to min
.
There are also dedicated sort methods for each sort type.
Pagination
Offset Pagination
Offset pagination returns total documents count as total
and current position as size/offset
.
Cursor pagination
current
, next
, previous
is returned in this case instead of total
, size
and offset
.
You can check Laravel docs for more info about cursor pagination.
Aggregation
Aggregaction queries can be created like this
Type of $aggs->price
is MinMax
.
Type of $aggs->codes
is BucketCollection
.
Aggregate names must be unique for whole query.
Aggregate types
Get all variants of attribute values:
Get min and max attribute values. E.g for date:
Aggregation plays nice with nested documents.
There is also a special virtual composite
aggregate on the root level. You can set special conditions using it.
Query Log
Just like Eloquent ElasticQuery has its own query log, but you need to enable it manually
Each message contains indexName
, query
and timestamp
Contributing
Please see CONTRIBUTING for details.
Testing
- composer install
- npm i
- Start Elasticsearch in your preferred way.
- Copy
phpunit.xml.dist
tophpunit.xml
and set correct env variables there - composer test
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
License
The MIT License (MIT). Please see License File for more information.