PHP code example of tamizh / laravel-es
1. Go to this page and download the library: Download tamizh/laravel-es library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
tamizh / laravel-es example snippets php artisan vendor:publish
Log::aggs(function($query){
$query->terms('field')->size(10)->minDocCount(10);
}, 'top_logs')
Log::aggs(function($query){
$query->terms('field')->size(10)->minDocCount(10);
}, 'top_logs')
->aggs(function($query){
$query->sum('field')
});
Log::aggs(function($query){
$query->terms('field')
->aggs(function($sub_query){
$sub_query->sum('field');
});
}, 'top_logs')
$results = Log::match('field', 'text')->size(100)->scroll();
foreach($results as $result){
// logic goes here
}
$log = Log::match('field', $text)->first();
$log->count = $log->count + 1;
$log->save();
$log = Log::match('field', $text)->first();
$log->delete();
$log = Log::queryString(function($query){
$query->query('tech*')
->fields(['errors', 'content']);
})->get();
Log::boolMust(function($query){
$query->queryString(function($query){
$query->query('tech*')
->fields(['errors', 'content']);
})
})->get();
Log::rangeBetween('error_rate', 20, 30)->get();
20 -> gte
30 -> lte
Log::aggs(function(){
$query->terms('user.id')-aggs(function(){
$query->topHits()->size(5); // get top 5 hits of the user
}, 'hits');
}, 'users')