ElasticSearch

Doc

Plugin


主機(jī)配置

1、單節(jié)點(diǎn)配置
$hosts = [
    // https://username:password@domain.com:9200/
    [
        'host' => 'domain.com',
        'port' => '9200',
        'scheme' => 'https',
        'user' => 'username',
        'pass' => 'password'
    ],

    // This is equal to "http://localhost:9200/"
    [
        'host' => 'localhost',    // Only host is required
    ]
];
2、多節(jié)點(diǎn)配置
$hosts = [
    '192.168.1.1:9200',         // IP + Port
    '192.168.1.2',              // Just IP
    'mydomain.server.com:9201', // Domain + Port
    'mydomain2.server.com',     // Just Domain
    'https://localhost',        // SSL to localhost
    'https://192.168.1.3:9200'  // SSL to IP + Port
];
3、創(chuàng)建客戶端對(duì)象
$clientBuilder = ClientBuilder::create();   // Instantiate a new ClientBuilder
$clientBuilder->setHosts($hosts);           // Set the hosts
$client = $clientBuilder->build();          // Build the client object
---monolog

composer.json添加monolog組件

{
    "require": {
        ...
        "elasticsearch/elasticsearch" : "~5.0",
        "monolog/monolog": "~1.0"
    }
}

更新composer

php composer.phar update

php code

$logger = ClientBuilder::defaultLogger('path/to/your.log');
// set severity with second parameter
// $logger = ClientBuilder::defaultLogger('/path/to/logs/', Logger::INFO);

$client = ClientBuilder::create()       // Instantiate a new ClientBuilder
            ->setLogger($logger)        // Set the logger with a default logger
            ->build();                  // Build the client object

defaultLogger()

use Monolog\Logger;
use Monolog\Handler\StreamHandler;

$logger = new Logger('name');
$logger->pushHandler(new StreamHandler('path/to/your.log', Logger::WARNING));

$client = ClientBuilder::create()       // Instantiate a new ClientBuilder
            ->setLogger($logger)        // Set your custom logger
            ->build();                  // Build the client object

Logstash


Search

GET {index}/{type}/_search
{
  "size": 0,
  "query": {
    "range": {
      "created_at": {
        "gte": "2018-02-01 00:00:00",
        "lte": "2018-02-02 00:00:00"
      }
    }
  },
  "aggs": {
    "data": {
      "date_histogram": {
        "field": "created_at",
        "interval": "hour",
        "format" : "yyyy-MM-dd HH",
        "min_doc_count": 0
      },
      "aggs": {
        "uvs": {
          "cardinality": {
            "field": "ip",
            "precision_threshold" : 100
          }
        }
      }
    }
  }
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容