ulff/elasticsearch-php-client-bundle 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

ulff/elasticsearch-php-client-bundle

最新稳定版本:2.3.0

Composer 安装命令:

composer require ulff/elasticsearch-php-client-bundle

包简介

A very simple bundle for integrating Symfony2.x/3.x with Elasticsearch-PHP 5.0

README 文档

README

Setting up bundle

Version Matrix

You need to match your version of Elasticsearch to the appropriate version of this library.

Bundle Version Elasticsearch Version
2.0 5.0
1.0 >= 1.0, ⇐ 5.0

Step 1: Install bundle

Install bundle using composer:

php composer.phar require "ulff/elasticsearch-php-client-bundle:2.0"

Enable the bundle in AppKernel.php:

// app/AppKernel.php

public function registerBundles()
{
    $bundles = [
        // ...
        new Ulff\ElasticsearchPhpClientBundle\UlffElasticsearchPhpClientBundle(),
    ];

    // ...
}

Step 2: add bundle configuration

Add following configuration to config.yml:

# app/config/config.yml

ulff_elasticsearch_php_client:
    elastic_host: "localhost"
    elastic_port: "9200"

Replace values with proper ones.

Usage

Client usage

Elasticsearch client is available as a service:

$client = $this->get('ulff_elasticsearch_php_client.client');

Create new index:

$indexParams = new IndexParams('index-name', 'type-name', 'id');
$indexParams->setBody(['someField' => 'some value']);
$response = $client->index($indexParams);

Returns IndexResponse object.

Get document:

$getParams = new GetParams('index-name', 'type-name', 'id');
$response = $client->get($getParams);

Returns GetResponse object.

Delete document:

$deleteParams = new DeleteParams('index-name', 'type-name', 'id');
$response = $client->delete($deleteParams);

Returns DeleteResponse object.

Delete by query:

$deleteParams = new DeleteByQueryParams('index-name', 'type-name');
$deleteParams->setBody([
   'query' => [
       'match_all' => new \stdClass(),
   ]
]);
$response = $client->deleteByQuery($deleteParams);

Returns DeleteByQueryResponse object.

Make search query:

$searchParams = new SearchParams('index-name', 'type-name');
$searchParams->setBody([
    'query' => [
        'match' => [
            'someField' => 'some value'
        ]
    ]
]);
$response = $client->search($searchParams);

Update document:

$updateParams = new UpdateParams('index-name', 'type-name', 'id');
$updateParams->setBody(['someField' => 'some value']);
$response = $client->update($updateParams);

Returns UpdateResponse object.

Purger usage

Bundle offers a possibility to purge whole index (by deleting and recreating empty). This can be useful e.g. for testing purposes.

There is a separate ulff_elasticsearch_php_client.purger service provided with the bundle. Following example shows how to purge index:

$purger = $this->get('ulff_elasticsearch_php_client.purger');
$purger->purgeIndex('index_name');

Full documentation:

This bundle is a client for:

Follow the documentation there.

License

This bundle is licensed under the MIT license. Please, see the complete license in the bundle LICENSE file.

统计信息

  • 总下载量: 12.23k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 4
  • 点击次数: 0
  • 依赖项目数: 2
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 3
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-02-12