xola / elasticsearch-proxy-bundle
一个充当Elasticsearch授权代理的Symfony2插件
v3.1
2020-11-03 08:29 UTC
Requires
- php: >=7.1
- ext-curl: *
- ext-json: *
- symfony/framework-bundle: >=2.1 <4.0
Requires (Dev)
- phpunit/phpunit: ^7
This package is not auto-updated.
Last update: 2024-09-28 16:41:27 UTC
README
一个充当Elasticsearch代理的Symfony2插件。
安装
使用composer,添加
{ "require": { "xola/elasticsearch-proxy-bundle" : "dev-master" } }
然后在您的内核中启用它
// app/AppKernel.php public function registerBundles() { $bundles = array( //... new Xola\ElasticsearchProxyBundle\XolaElasticsearchProxyBundle(), //...
配置
# app/config/config.yml xola_elasticsearch_proxy: client: protocol: http host: localhost port: 9200 indexes: ['logs']
indexes
参数允许您仅授权访问指定的Elasticsearch索引。
路由
更新您的路由
# app/config/routing.yml # Xola elasticsearch proxy XolaElasticsearchProxyBundle: resource: "@XolaElasticsearchProxyBundle/Resources/config/routing.yml" prefix: /
默认路径是 /elasticsearch
,允许所有HTTP方法(GET、PUT、POST等)。
覆盖它。确保 index
(捕获Elasticsearch索引)和 slug
(捕获URL的其余部分)保留在路由模式中。
# app/config/routing.yml xola_elasticsearch_proxy: pattern: /myproxy/{index}/{slug} defaults: { _controller: XolaElasticsearchProxyBundle:ElasticsearchProxy:proxy } requirements: slug: ".+"
事件
该插件控制器会触发一些事件,可以帮助您。通过监听这些事件,您可以添加任何所需的自定义身份验证或过滤逻辑。
-
elasticsearch_proxy.before_elasticsearch_request
- 在请求发送到Elasticsearch之前触发此事件。监听器将接收到包含请求、索引、slug和查询对象的ElasticsearchProxyEvent
。您可以修改此查询对象,并使用setQuery
将其设置回事件。然后,更新后的请求将发送到Elasticsearch。 -
elasticsearch_proxy.after_elasticsearch_response
- 在从Elasticsearch收到响应后触发此事件。监听器将接收到包含请求、索引、slug、查询和响应对象的ElasticsearchProxyEvent
。您可以修改响应并将其设置回事件。然后,更新后的响应将发送回客户端。