🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
[TOC] > [github](https://github.com/elastic/elasticsearch-php) > [官方手册](https://www.elastic.co/guide/cn/elasticsearch/php/current/_configuration.html) ## 安装 ``` "require": { "elasticsearch/elasticsearch": "^7.0" } ```` ## 配置 ``` $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 ]; $client = ClientBuilder::create() // Instantiate a new ClientBuilder ->setHosts($hosts) // Set the hosts ->build(); // Build the client object ``` or ``` $hosts = [ // This is effectively equal to: "https://username:password!#$?*abc@foo.com:9200/" [ 'host' => 'foo.com', 'port' => '9200', 'scheme' => 'https', 'user' => 'username', 'pass' => 'password!#$?*abc' ], // This is equal to "http://localhost:9200/" [ 'host' => 'localhost', // Only host is required ] ]; $client = ClientBuilder::create() // Instantiate a new ClientBuilder ->setHosts($hosts) // Set the hosts ->build(); // Build the client object ``` ## 开启日志 官方推荐使用 mogodb ``` { "require": { ... "elasticsearch/elasticsearch" : "~6.0", "monolog/monolog": "~1.0" } } ``` `composer update` ```$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 ```