.. include:: ../services/es.rst 使用 PHP 客户端连接 ====================== 在 PHP 中,可以使用官方提供的 Elasticsearch-PHP 客户端对新浪云 Elasticsearch 进行操作。 首先需要使用 composer 安装库文件,需要注意的是,官方客户端只支持 PHP 5.4 以上环境,所以需要将 PHP 版本切换到 5.6。如果当前系统中没有 composer,可以参考 :doc:`composer-intro` 安装。 .. code-block:: console $ composer require "elasticsearch/elasticsearch" 安装完成后,可以创建 ``test_es.php`` 内容如下: .. code-block:: php setHosts($hosts)->build(); $params = [ 'index' => '索引名', 'type' => 'my_type', 'id' => 'my_id', 'body' => ['testField' => 'abc'] ]; $response = $client->index($params); print_r($response); $params = [ 'index' => '索引名', 'type' => 'my_type', 'body' => ['query' => ['match' => ['testField' => 'abc']]] ]; $response = $client->search($params); print_r($response); 更多的详细信息,可以参考 `官方文档 `_