Download the PHP package isswp101/elasticsearch-eloquent without Composer
On this page you can find all versions of the php package isswp101/elasticsearch-eloquent. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download isswp101/elasticsearch-eloquent
More information about isswp101/elasticsearch-eloquent
Files in isswp101/elasticsearch-eloquent
Package elasticsearch-eloquent
Short Description Elasticsearch functionality like Laravel Eloquent models.
License MIT
Informations about the package elasticsearch-eloquent
Elasticsearch Eloquent 2.x
This package allows you to interact with Elasticsearch as you interact with Eloquent models in Laravel.
Requirements
- PHP >= 8.0
- Elasticsearch >= 7.0
Install
Via Composer
Usage
Create a new model
You should override index
and type
properties to determine the document path.
Use the static create()
method to create the document in Elasticsearch:
Save the model
Use save()
method to store model data in Elasticsearch. Let's see how this looks in Elasticsearch:
Fields created_at
and updated_at
were created automatically.
Find existing model
If you have big data in Elasticsearch you can specify certain fields to retrieve:
There are the following methods:
findOrFail()
returnsModelNotFoundException
exception if no result found.
Cache
There is a smart model cache when you use methods like find()
, findOrFail()
and so on.
Partial update
You can use the partial update to update specific fields quickly.
Delete models
You can use the static method:
Model events
Out of the box you are provided with a simple implementation of events.
You can override the following methods to define events:
saving()
is called before saving, updating, creating the modelsaved()
is called after saving, updating, creating the modeldeleting()
is called before deleting the modeldeleted()
is called after deleting the modelsearching()
is called after searching modelssearched()
is called after searching models
For example:
Basic search
There are helpers to search documents:
The first($query)
method returns the first document according to the query or null
.
The firstOrFail($query)
method returns ModelNotFoundException
exception if first($query)
returns null
.
The search($query)
method returns documents according to the query.
The all($query)
method returns all documents (default 50 items per request) according to the query.
If $query
is not passed the query will be as match_all
query.
Query Builder
Consider using these packages:
Testing
License
The MIT License (MIT).