pedromdev/elasticsearch-module

Zend Framework 2 的 Elasticsearch 模块

v1.0.2 2017-03-05 22:41 UTC

This package is not auto-updated.

Last update: 2024-09-28 22:26:18 UTC


README

Build Status Scrutinizer Code Quality Coverage Status

Elasticsearch-PHP 客户端与 Zend Framework 2 之间的集成

安装

安装通过 Composer 完成。在 composer.json 中添加依赖项

{
    "require": {
        "pedromdev/elasticsearch-module": "~1.0"
    }
}

然后运行安装命令

php composer.phar install --no-dev

或者运行更新命令,如果您已经安装了该软件包

php composer.phar update --no-dev

Composer 安装所有依赖项后,将 ElasticsearchModule 添加到 application.config.php

<?php

return [
    'modules' => [
        'ElasticsearchModule',
    ],
];

ElasticsearchModule 服务和配置

注意:这些服务和配置基于 DoctrineModule/DoctrineORMModule 的服务和配置。

服务

已注册服务

  • elasticsearch.loggers.default:一个包含 \Psr\Log\LoggerInterface 实例的 \ArrayObject 实例。每个实例都与日志配置中的一个键相关联;
  • elasticsearch.handler.default:默认中间件可调用对象;
  • elasticsearch.connection_factory.default:一个 \Elasticsearch\Connections\ConnectionFactoryInterface 实例;
  • elasticsearch.connection_pool.default:一个 \Elasticsearch\ConnectionPool\AbstractConnectionPool 实例;
  • elasticsearch.transport.default:一个 \Elasticsearch\Transport 实例;
  • elasticsearch.endpoint.default:默认可调用对象,用于检索一个 \Elasticsearch\Endpoints\AbstractEndpoint 实例。它的唯一参数是一个端点类名(例如,Get、Bulk、Delete);
  • elasticsearch.client.default:一个 \Elasticsearch\Client 实例;
  • Elasticsearch\Client:是 elasticsearch.client.default 的别名。

使用

<?php

$client = $serviceLocator->get('elasticsearch.client.default');
$client = $serviceLocator->get('Elasticsearch\Client');

配置

创建一个包含以下内容的 config/autoload/elasticsearch.global.php 文件

<?php

return [
    'elasticsearch' => [
        'connection_pool' => [
            'default' => [
                'hosts' => [
                    'https://:9200', // string based
                    'http://username:password@localhost:9200', // if you have an authentication layer
                    [
                        'scheme' => 'http', // associative array based
                        'host' => 'localhost',
                        'port' => 9200,
                        'user' => 'username', // if you have an authentication layer
                        'pass' => 'password',
                    ],
                ],
            ],
        ],
    ],
];