PHP code example of ritaswc / elk-query-client

1. Go to this page and download the library: Download ritaswc/elk-query-client 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/ */

    

ritaswc / elk-query-client example snippets


    $url    = 'http://172.16.121.32:9200';
    $client = new QueryClient($url, 'tiger_logs');
    $list   = [];
    $client->query(['keyword for search'], function (array $item) use (&$list) {
        $logContent = trim($item['fields']['event.original'][0] ?? '');
        $logContent = mb_substr($logContent, mb_strpos($logContent, '{'));
        $arr        = json_decode($logContent, true);
        if (is_array($arr)) {
            $manualType = $arr['manualType'] ?? '';
            if (strlen($manualType)) {
                $list[$manualType] = $manualType;
            }
        }
    }, [strtotime('2025-01-01 00:00:00'), time()]);
    dd($list);