1、在 composer.json 文件中引入 elasticsearch-php:
{ "require":{ "elasticsearch/elasticsearch":"~6.0", "monolog/monolog": "~1.0" } }
2、用 composer 安装客户端:
curl -s http://getcomposer.org/installer | php php composer.phar install --no-dev
1、创建一个test.php文件,内容如下
<?php require ‘vendor/autoload.php‘; use Elasticsearch\ClientBuilder; $hosts = [ ‘192.168.16.241:9200‘, // IP + Port ‘192.168.16.241‘, // Just IP ‘localhost:9200‘, // Domain + Port ‘localhost‘, // Just Domain ‘http://localhost‘, // SSL to localhost ‘https://192.168.16.241:9200‘ // SSL to IP + Port ]; $client = ClientBuilder::create()->setHosts($hosts)->build(); // Instantiate a new ClientBuilder // Set the hosts $params = [ ‘index‘ => ‘test_data‘, ‘type‘ => ‘users‘, ‘id‘ => 100027, ‘client‘ => [ ‘ignore‘ => 404 ] ]; var_dump( $client->get($params));
2、浏览器访问test.php,结果如下(前提是你的es已经有数据)
原文:https://www.cnblogs.com/killer21/p/12179936.html