Download the PHP package ensi/laravel-elastic-query without Composer

On this page you can find all versions of the php package ensi/laravel-elastic-query. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-elastic-query

Laravel Elastic Query

Latest Version on Packagist Tests Total Downloads

Working with Elasticsearch in an Eloquent-like fashion.

Installation

You can install the package via composer:

Publish config file like this:

Set ELASTICSEARCH_HOSTS in your .env file. , can be used as a delimeter.

Version Compatibility

Laravel Elastic Query Laravel PHP Elasticsearch
^0.1.0 ^8.0 ^8.0 7.*
^0.2.0 ^8.0 ^8.0 7.*
^0.3.0 ^8.0 ^8.0 7.*
^0.3.2 ^8.0 || ^9.0 ^8.0 7.*
^7.x (see details) ^9.0 || ^10.0 || ^11.0 ^8.1 7.*
^8.0.0 ^8.0 || ^9.0 ^8.0 8.*
^8.0.13 ^8.0 || ^9.0 || ^10.0 ^8.0 8.*
^8.0.23 ^8.0 || ^9.0 || ^10.0 || ^11.0 ^8.0 8.*
^8.1.0 ^9.0 || ^10.0 || ^11.0 ^8.1 8.*

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.

Full text search

field_one and field_two must be of text type. If no type is given, the MatchType::BEST_FIELDS is used.

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:

Get count unique attribute values:

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.

Suggesting

Suggest queries can be created like this

Global suggest text

User can set global text like this

Suggester types

Term suggester:

Phrase Suggester:

Additional methods

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

Environment Variables

Below see the environment variables that you can configure with the default values, Hosts should be comma seperated string of hosts with protocol prefix and port suffix, e.g. http://localhost:9200,http://localhost:9201

Async Usage

All methods can return a Promise.
To enable this, you will need to add http_async_client to your config and then execute ElasticSearch::getClient()->setAsync(true).
To disable: ElasticQuery::getClient()->setAsync(false).

For example:

laravel-elastic-query.php:

HttpClientOptionsBuilder:

Action:

Elasticsearch 7 and 8 support.

Due to the incompatibility of clients for Elasticsearch 7 and 8, separate releases will be created for these versions. Development for each version is carried out in the corresponding branch.

To make changes to version 7, you need to create a task branch based on v7 and make a pull request to it. For version 8 it is similar, but based on the v8 branch.

Contributing

Please see CONTRIBUTING for details.

Testing

  1. composer install
  2. start Elasticsearch in your preferred way
  3. if you need change ELASTICSEARCH_HOSTS, copy phpunit.xml.dist to phpunit.xml and fill value
  4. 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.


All versions of laravel-elastic-query with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
elasticsearch/elasticsearch Version ^8.0
laravel/framework Version ^9.0 || ^10.0 || ^11.0
webmozart/assert Version ^1.11
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package ensi/laravel-elastic-query contains the following files

Loading the files please wait ....