Elastic Search

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.

Basic Methods

get($id:string,$key:string);


    $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
    )
    */
    

save($type:string,$data:array,$id:string);


    $user = $app->get("elastic")->save('users',[
        'firstname'=>'Daniel',
        'lastname'=>'Johnson',
        'age'=>21
    ]);
    

update($id:string,$data:array);


    $user = $app->get("elastic")->update("882924324",[
        'firstname'=>'daniel',
        'lastname'=>'johnson',
        'age'=>17
    ]);
    

delete($id:string);


    $user = $app->get("elastic")->delete("882924324");
    
    

Advanced Methods

Parameters
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
Query Details
Name Description Examples
and Array of Dependent "Must" Clause elements

'and'=>[
    ['age','>',29],
    ['firstname','!=','Daniel']
]
//WHERE age > 29 AND firstname != Daniel
            
or Array of Independent "Should" Clause elements

'or'=>[
    ['age','=',28],
    ['age','<',10],
]
//WHERE age = 28 OR age < 10
            
Search Return Object
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
                    )
            )
    )

count($type:string,$query:array);


    $user = $app->get("elastic")->count('users');
    print_r($user);

    //OUTPUTS INTEGER COUNT
    1
    

search($type:string,$query:array,$max:integer,
$start:integer,$order:string,$sort:string,$after:string);


    $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
    )
    */
    

Query Examples

Search "And" Group


    $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
                    )
            )
    )
    */
    

Search Pagination & Sorting


    $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
                    )
            )
    )
    */