caxy/elasticsearch-bundle

Symfony Elasticsearch 扩展包

安装: 41

依赖者: 0

建议者: 0

安全性: 0

星标: 0

关注者: 24

分支: 2

类型:symfony-bundle

0.0.1 2013-10-30 14:42 UTC

This package is auto-updated.

Last update: 2024-09-22 07:07:36 UTC


README

使用 'config.yml' 创建 Elasticsearch 客户端

安装

composer.json

# composer.json

"require": {
	"caxy/elasticsearch-bundle": "0.0.*"
	...
}

并运行 composer update 命令。

AppKernel.php

# app/AppKernel.php

public function registerBundles()
{
    bundles = array(
        // ...
        new Caxy\Bundle\ElasticsearchBundle\CaxyElasticsearchBundle(),
    );
    
    retrun bundles();
}

配置

config.yml

# app/config/config.php

caxy_elasticsearch:
    client:
        default:
            hosts: [ "localhost" ] # Require
        named:
            class: Your\Elasticsearch\Client
            hosts: [ "localhost", "127.0.0.1","localhost:9200", "127.0.0.1:9201" ]
            log_path: elasticsearch.log # Optional
            log_level: Logger::WARNING # Optional

默认值

@see Elasticsearch PHP API - 全部配置列表-

使用方法

从服务中获取客户端。

使用默认设置 Elasticsearch 客户端。

# Bundle/Controller/Controller.php

public function fooAction()
{
    $es = $this->container->get('caxy_elasticsearch_client');
    // or
    $es = $this->container->get('caxy_elasticsearch_client.default');
}

使用命名设置。

# Bundle/Controller/Controller.php

public function fooAction()
{
    $es = $this->container->get('caxy_elasticsearch_client.named');
    get_class($es); // Your\Elasticsearch\Client
}

客户端

@see elasticsearch/elasticsearch 网站文档