Elastic Search is a distributed, JSON-based search and analytics engine. It's one of the fastest big data open source platforms available today, and is a powerful database tool.
The strategy of the PAX Elastic Class is to promote minimalism and JSON friendly conversion. As such array structures are implemented for language speed and immediate ease of interaction across all languages.
$user = $app->get("elastic")->get("882924324");
print_r($user);
/*
OUTPUTS
Array
(
[firstname]=>John
[lastname]=>Smith
[age]=>28
[id]=>882924324
)
*/
$user = $app->get("elastic")->get("Smith","lastname");
print_r($user);
/*
OUTPUTS
Array
(
[firstname]=>John
[lastname]=>Smith
[age]=>28
[id]=>882924324
)
*/
$user = $app->get("elastic")->save('users',[
'firstname'=>'Daniel',
'lastname'=>'Johnson',
'age'=>21
]);
$user = $app->get("elastic")->update("882924324",[
'firstname'=>'daniel',
'lastname'=>'johnson',
'age'=>17
]);
$user = $app->get("elastic")->delete("882924324");
Name | Type | Default | Description |
---|---|---|---|
$type | String | Name of Type (Table) Querying | |
$query | Array | Associative array used to define the query's must, should, join clauses |
|
$max | Integer | 10 | Total amount of results to return |
$start | Integer | 0 | Pagination position to start. |
$sort | String | 'asc' | Sorting of Results |
$order | String | 'id' | Field to sort by |
Name | Description | Examples |
---|---|---|
and | Array of Dependent "Must" Clause elements |
|
or | Array of Independent "Should" Clause elements |
|
Name | Type | Description |
---|---|---|
count | Integer | The total count of results independent of pagination |
hits | Array | Results dependent on pagination |
Array
(
[count] => 2
[hits] => Array
(
[0] => Array
(
[firstname] => John
[lastname] => Smith
[age]=>28
)
[1] => Array
(
[firstname] => Daniel
[lastname] => Johnson
[age]=>17
)
)
)
$user = $app->get("elastic")->count('users');
print_r($user);
//OUTPUTS INTEGER COUNT
1
$user = $app->get("elastic")->search('users');
print_r($user);
/*OUTPUT
Array
(
[count] => 2
[hits] => Array
(
[0] => Array
(
[firstname] => John
[lastname] => Smith
[age]=>28
)
[1] => Array
(
[firstname] => Daniel
[lastname] => Johnson
[age]=>17
)
)
)
*/
$user = $app->get("elastic")->search('users',[
['lastname','=','Smith']
]);
print_r($user);
/*OUTPUT
(
[firstname] => John
[lastname] => Smith
[age]=>28
)
*/
$user = $app->get("elastic")->search('users',[
'and'=>[
['age','>',20],
['firstname','!=','Daniel']
]
]);
print_r($user);
//SELECT * FROM users WHERE age > 20 AND firstname != Daniel
/*OUTPUT
Array
(
[count] => 1
[hits] => Array
(
[0] => Array
(
[firstname] => John
[lastname] => Smith
[age]=>28
)
)
)
*/
$user = $app->get("db")->search('users',[],2,1,'asc','firstname');
print_r($user);
//SELECT * FROM users LIMIT 2 OFFSET 1
/*OUTPUT
Array
(
[count] => 4
[hits] => Array
(
[0] => Array
(
[firstname] => Paul
[lastname] => Rudd
[age]=>24
)
[1] => Array
(
[firstname] => Zach
[lastname] => Galifianakis
[age]=>32
)
)
)
*/