Download the PHP package matchish/laravel-scout-elasticsearch without Composer

On this page you can find all versions of the php package matchish/laravel-scout-elasticsearch. 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-scout-elasticsearch

Stay with Ukraine

UNITED24 launches the first fundraiser towards terrestrial robotic platforms. Squads of robots will save the lives of our military and civilians. They will become logistics devices, tow trucks, minelayers and deminers, as well as self-destructive robots. They will fight alongside people and for people. The first robots are already proving their effectiveness on the battlefield. There will be more of them soon. Many more.

Support Ukraine Import progress report

Coverage Total Downloads Latest Version License

For Laravel Framework < 6.0.0 use 3.x branch

The package provides the perfect starting point to integrate ElasticSearch into your Laravel application. It is carefully crafted to simplify the usage of ElasticSearch within the Laravel Framework.

It’s built on top of the latest release of Laravel Scout, the official Laravel search package. Using this package, you are free to take advantage of all of Laravel Scout’s great features, and at the same time leverage the complete set of ElasticSearch’s search experience.

:two_hearts: Features

Don't forget to :star: the package if you like it. :pray:

Elasticsearch version ElasticsearchDSL version
>= 8.0 >= 8.0.0
>= 7.0 >= 3.0.0
>= 6.0, < 7.0 < 3.0.0

:rocket: Installation

Use composer to install the package:

Set env variables

The package uses \ElasticSearch\Client from official package, but does not try to configure it beyond connection configuration, so feel free do it in your app service provider. But if you don't want to do it right now, you can use Matchish\ElasticSearchServiceProvider from the package.
Register the provider, adding to config/app.php

Set ELASTICSEARCH_HOST env variable

or use commas as separator for additional nodes

You can disable SSL verification by setting the following in your env

And publish config example for elasticsearch
php artisan vendor:publish --tag config

:bulb: Usage

Note: This package adds functionalities to Laravel Scout, and for this reason, we encourage you to read the Scout documentation first. Documentation for Scout can be found on the Laravel website.

Index settings and mappings

It is very important to define the mapping when we create an index — an inappropriate preliminary definition and mapping may result in the wrong search results.

To define mappings or settings for index, set config with right value.

For example if method searchableAs returns products string

Config key for mappings should be
elasticsearch.indices.mappings.products
Or you you can specify default mappings with config key elasticsearch.indices.mappings.default

Same way you can define settings

For index products it will be
elasticsearch.indices.settings.products

And for default settings
elasticsearch.indices.settings.default

Eager load

To speed up import you can eager load relations on import using global scopes.

You should configure ImportSourceFactory in your service provider(register method)

Here is an example of MyImportSourceFactory

You can also customize your indexed data when you save models by leveraging the toSearchableArray method provided by Laravel Scout through the Searchable trait

Example:

This example will make sure the categories relationship gets always loaded on the model when saving it.

Zero downtime reimport

While working in production, to keep your existing search experience available while reimporting your data, you also can use scout:import Artisan command:

php artisan scout:import

The command create new temporary index, import all models to it, and then switch to the index and remove old index.

Search

To be fully compatible with original scout package, this package does not add new methods.
So how we can build complex queries? There is two ways.
By default, when you pass a query to the search method, the engine builds a query_string query, so you can build queries like this

If it's not enough in your case you can pass a callback to the query builder

Note : The callback function will get 2 parameters. First one is $client and it is an object of \Elastic\Elasticsearch\Client class from elasticsearch/elasticsearch package. And the second one is $body which is an object of \ONGR\ElasticsearchDSL\Search from ongr/elasticsearch-dsl package. So, while as you can see the example above, $client->search(....) method will return an \Elastic\Elasticsearch\Response\Elasticsearch object. And you need to use asArray() method to get array result. Otherwise, the HitsIteratorAggregate class will throw an error. You can check the issue here.

Conditions

Scout supports only 3 conditions: ->where(column, value) (strict equation), ->whereIn(column, array) and ->whereNotIn(column, array):

Scout does not support any operators, but you can pass ElasticSearch terms like RangeQuery as value to ->where():

And if you just want to search using RangeQuery without any query_string, you can call the search() method directly and leave the param empty.

Full list of ElasticSearch terms is in vendor/handcraftedinthealps/elasticsearch-dsl/src/Query/TermLevel.

Pagination

The engine supports Elasticsearch pagination with Scout Builder pagination or by setting page sizes and offsets using the ->take($size) method and ->options(['from' => $from]).

Caution : Builder pagination takes precedence over the take() and options() setting.

For example:

This will return the first 50 results, ignoring the specified offset.

Search amongst multiple models

You can do it with MixedSearch class, just pass indices names separated by commas to the within method.

In this example you will get collection of Ticket and Book models where ticket's arrival city or book title is Barcelona

Working with results

Often your response isn't collection of models but aggregations or models with higlights an so on. In this case you need to implement your own implementation of HitsIteratorAggregate and bind it in your service provider

Here is a case

:free: License

Scout ElasticSearch is an open-sourced software licensed under the MIT license.


All versions of laravel-scout-elasticsearch with dependencies

PHP Build Version
Package Version
No informations.
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 matchish/laravel-scout-elasticsearch contains the following files

Loading the files please wait ....