bangpound/elasticsearch-bundle

该包已被废弃,不再维护。作者建议使用 caxy/elasticsearch-bundle 包代替。

Symfony Elasticsearch Bundle

安装: 15

依赖者: 0

建议者: 0

安全: 0

星标: 0

关注者: 24

分支: 2

类型:symfony-bundle

0.0.1 2013-10-30 14:42 UTC

This package is not auto-updated.

Last update: 2022-02-01 12:28:10 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 网站文档