Project Name | Stars | Downloads | Repos Using This | Packages Using This | Most Recent Commit | Total Releases | Latest Release | Open Issues | License | Language |
---|---|---|---|---|---|---|---|---|---|---|
Spring Boot Demo | 28,300 | 3 months ago | 110 | mit | Java | |||||
🚀一个用来深入学习并实战 Spring Boot 的项目。 | ||||||||||
Ebean | 1,372 | 100 | 32 | a day ago | 113 | August 02, 2016 | 50 | apache-2.0 | Java | |
Ebean ORM | ||||||||||
Easy Es | 881 | 5 days ago | 17 | May 27, 2022 | 23 | apache-2.0 | Java | |||
An easier-to-use elasticsearch engine framework, the bottom layer adopts RestHighLevelClient, API design consistent with Mybatis-plus, zero additional learning cost, shielding language differences, developers only need to know MySQL syntax to complete Es-related operations, both Low code, easy to use, easy to expand and other features, support Es unique highlighting, weighting, word segmentation, Geo and other functions... | ||||||||||
Hibernate Search | 449 | 840 | 55 | 2 days ago | 141 | October 18, 2021 | 2 | other | Java | |
Hibernate Search: full-text search for domain model | ||||||||||
Elasticsearch | 375 | 6 | 2 years ago | 42 | December 24, 2019 | 63 | mit | PHP | ||
The missing elasticsearch ORM for Laravel, Lumen and Native php applications | ||||||||||
Fs | 268 | 13 | 15 days ago | 7 | January 10, 2023 | 1 | mit | Go | ||
farseer-go all components of the base module, module launcher, framework initialization program(所有组件的基础模块,模块启动器,框架初始化程序) | ||||||||||
Express Cassandra | 194 | 76 | 26 | 4 months ago | 96 | March 11, 2022 | 31 | lgpl-3.0 | JavaScript | |
Cassandra ORM/ODM/OGM for Node.js with optional support for Elassandra & JanusGraph | ||||||||||
Sherlock | 122 | 8 | 2 | 7 years ago | 17 | October 26, 2013 | 25 | mit | PHP | |
Elasticsearch | 101 | 2 years ago | n,ull | mit | PHP | |||||
Use SQL statements to query elasticsearch | ||||||||||
Pydastic | 86 | 5 months ago | 6 | May 08, 2022 | 46 | mit | Python | |||
An Elasticsearch Python ORM based on Pydantic. |
This is a simple ORM mapper for ElasticSearch for PHP.
ElasticSearch DSL query builder for PHP.
If you can join me in updating and maintaining this project, please send a message to [email protected]
composer require itvisionsy/php-es-orm
Head to the latest version here then download using one download button.
For the Query Builder, read this README instead
That is simple:
::find($type, $id)
, ::query($type, array $query =[])
, and ::all($type)
You will get a list of Model objects where you can object-property access to get all the info.
i.e. $model->name
to get the name property, ...TypeQueryInterface
interface and use the TypeQueryTrait
trait::find($id)
, ::all()
, and ::query(array $query=[])
.
You will get a list of Model objects the same way described above.Methods' parameters are mapped to original elasticsearch methods and parameters as follows:
::find(scalar)
and ::find(scalar[])
methods are mapped to [get](https://github.com/elastic/elasticsearch-php/blob/master/src/Elasticsearch/Client.php# L167) and [mget](https://github.com/elastic/elasticsearch-php/blob/master/src/Elasticsearch/Client.php# L671) methods respectively.::query
method is mapped to the [search](https://github.com/elastic/elasticsearch-php/blob/master/src/Elasticsearch/Client.php# L1002) method, and the $query param will be passed as is after appending the index and type parameters to it.The query class is just a simple interface allows you to send DSL queries, or perform other ElasticSearch requests.
The ::query()
method for example will expect to receive an assoc-array with a well-formed DSL query.
However, you can use the query builder to builder the query and get a well-formed DSL array out of it.
You can use a type-query query builder to build the query and execute it directly:
$result = TypeQuery::builder()
->where('key1','some value')
->where('key2',$intValue,'>')
->where('key3','value','!=')
->where('key4', ['value1','value2'])
->execute();
//$result is a \ItvisionSy\EsMapper\Result instance
Or you can use a generic query builder to build the query then you can modify it using other tools:
//init a builder object
$builder = \ItvisionSy\EsMapper\QueryBuilder::make();
//build the query using different methods
$query = $builder
->where('key1','some value') //term clause
->where('key2',$intValue,'>') //range clause
->where('key3','value','!=') //must_not term clause
->where('key4', ['value1','value2']) //terms clause
->where('email', '@hotmail.com', '*=') //wildcard search for all @hotmail.com emails
->sort('key1','asc') //first sort option
->sort('key2',['order'=>'asc','mode'=>'avg']) //second sort option
->from(20)->size(20) //results from 20 to 39
->toArray();
//modify the query as you need
$query['aggs']=['company'=>['terms'=>['field'=>'company']]];
//then execute it against a type query
$result = TypeQuery::query($query);
//$result is a \ItvisionSy\EsMapper\Result instance
Please refer to this file for more detailed information.
The returned result set implements the ArrayAccess interface to access specific document inside the result. i.e.
$result = SomeQuery::all();
You can then get a document like this:
$doc = $result[1]; //gets the second document
Or you can use the dot notation like that:
$result->fetch('hits.hits.0'); //for any absolute access
On the model object, you can access the results in many ways:
$object->attribute
$object->getAttributes()[attribute]
, as the getAttributes() will return the document data as an array (first level only).$object->getAttributes($attribute1, $attribute2, ...)
which will return a single (or array) value[s] depending on the requested attributesEither way will work:
Use the index query static method
IndexQuery::create(array $data, $type, $id=null, array $parameters=[])
Use the type query static method:
TypeQuery::create(array $data, $id=null, array $parameters=[])
You can update an already indexed document by:
update(array $data, array $parameters=[])
method on the model's object:TypeQuery::find(1)->update(['new_key'=>'value','old_key'=>'new value'],[]);
The same way you can update a document, you can delete it:
::delete($type, $id)
on the index query->delete()
on model's object.You may need to add extra custom methods like top($numOfDocs)
or anything else.
To do so, you need to create the method name you wish as protected in the query sub-class. The name should be prefixed with _ (i.e. _top
) then, you can either
Call it prefixed with get
, so to call the _top(500)
method, just call getTop(500)
and it will be mapped as public static and as public.
Override the _allowPublicAccess
static protected method to add extra methods to expose.
Please note that when overriding, don't forget to merge with the parent results not to lose the old ones:
protected _allowPublicAccess(){
return array_merge(parent::_allowPublicAccess(), ['top','any',...]);
}
This way you will save the allowed methods from the parent.
You can extend the Model class easily. Just extend it!
In case you were using the namespaces, you can set the models namespace in the query class by overriding the modelNamespace public method. This method should return a string ending with
After that, you need to call the ->setModelClass($class)
on the query result object.
Please check tests/ folder. Basically, the case1.php is the main file.
\
|
+-- TestsIndexQuery (TestsIndexQuery.php) Main index query class.
| | Maps results to \Models\ namespace.
| |
| +-- \FooTypeQuery (FooTypeQuery.php) Type index query class.
| |
| +-- \BarTypeQuery (BarTypeQuery.php) Type index query class.
|
|-- Models\
|
+-- Foo (FooMode.php) Foo model class
|
+-- Bar (BarModel.php) Bar model class
This code is published under MIT license.