Download the PHP package earc/data-elasticsearch without Composer
On this page you can find all versions of the php package earc/data-elasticsearch. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download earc/data-elasticsearch
More information about earc/data-elasticsearch
Files in earc/data-elasticsearch
Package data-elasticsearch
Short Description eArc - the explicit architecture framework - data elasticsearch component
License MIT
Informations about the package data-elasticsearch
eArc-data-elasticsearch
Elasticsearch-bridge for the earc/data persistence handler.
table of contents
- installation
- basic usage
- bootstrap
- initialize index
- search
- enhanced syntax
- range
- match
- text
- exists
- _id
- embedded entity
- embedded entity collection (nested)
- joins
- raw query
- raw search body
- advanced usage
- index name
- entity whitelist and blacklist
- extend the elasticsearch bridge
- releases
- release 0.0
installation
Install the earc data elasticsearch library via composer.
basic usage
bootstrap
Initialize the earc/data package.
If your elasticsearch server is not located at localhost:9200
or you need to
authenticate, you have to configure it.
Then register the earc/data-elasticsearch bridge.
Now your entities will be indexed and removed from the index automatically. You are ready to search your earc/data entities via elasticsearch.
initialize index
If you have persisted entities before installing the earc/data-elasticsearch bridge,
you can use IndexService::rebuildIndex()
to index the entities that are in your
data-store already.
This has to be done only once. New entities and updates are indexed automatically.
search
To search is very straight forward.
This would find all entities of the MyUserEntitiy
class with a name
property of
Max
or Moritz
and an age
property of 21
.
If you don't need the primary keys data_find_entities
is shorter.
To find all existing primary keys use the empty array.
enhanced syntax
earc/data-elasticsearch supports more than the complete earc/data data_find
syntax.
From the support for ranges and full text search to every elasticsearch query possible.
This one size fits all approach is simple to start with, but as hard as the
elasticsearch dsl to master.
range
The use of the range is done via a ..range
postfix.
This gives an open range above 18.
Closed ranges are possible too.
match
To perform a full text search (use the elasticsearch verb match
against a
text
field) use the ..match
postfix.
text
The ..text
postfix gives a keyword (term
) search against a text
field. This
becomes handy if you search a single word but doesn't know if your target
is uppercase, lowercase or uppercase first.
exists
Elasticsearch does not know null
values. Instead of IS NOT NULL
you can check
if a property exists, which is in most cases the same.
Or check if a property does not exist, which is similar to IS NULL
.
_id
The getter getPrimaryKey()
is used as elasticsearch document id. Thus, you can
use the property _id
to test against one or more primary keys.
embedded entity
To query embedded entities you can use the dot syntax.
embedded entity collection (nested)
Embedded entity collections have two properties _entityName
and _items
. _items
invoke a nested query.
joins
Elasticsearch does not know joins, but they can be realized via two separate queries.
This works for one-to-one and many-to-one relations.
If your joined entity uses a collection e.g. the join represents a one-to-many
or a many-to-many relation, then you have to use the .items
embedded syntax.
raw query
You can always call upon the raw power of the elasticsearch dsl via the .raw
postfix.
raw search body
To write the complete search in the elasticsearch dsl use the .raw_body
key.
advanced usage
index name
The indices of the entities are named earc-data-
plus the lowercase version
of the fully qualified class name where the backslash \\
is replaced by
the minus sign -
. The earc-data
prefix can be configured.
entity whitelist and blacklist
All entities are indexed by default. This can be changed via whitelisting or blacklisting.
Only the entities on the whitelist will be indexed.
All but the entities on the blacklist will be indexed.
If black- and whitelist is configured the whitelist is used only.
extend the elasticsearch bridge
To extend the elasticsearch bridge just decorate one of its classes.
Since there are only three classes (DocumentFactory
, ElasticsearchDataBridge
and
IndexService
) copy and pasting them into your project is a reasonable option.
releases
release 0.0
- the first official release
- php ^8.0 support
- elasticsearch ^7.0 support