xola / elasticsearch-proxy-bundle
A Symfony2 plugin that acts as an authorization proxy for elasticsearch
Installs: 13 685
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 6
Forks: 4
Open Issues: 2
Type:symfony-bundle
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: 2025-04-12 19:07:49 UTC
README
A Symfony2 plugin that acts as a proxy for Elasticsearch.
Installation
With composer, add:
{ "require": { "xola/elasticsearch-proxy-bundle" : "dev-master" } }
Then enable it in your kernel:
// app/AppKernel.php public function registerBundles() { $bundles = array( //... new Xola\ElasticsearchProxyBundle\XolaElasticsearchProxyBundle(), //...
Configuration
# app/config/config.yml xola_elasticsearch_proxy: client: protocol: http host: localhost port: 9200 indexes: ['logs']
The indexes
parameter lets you grant access to only the specified elasticsearch indexes.
Routing
Update your routing
# app/config/routing.yml # Xola elasticsearch proxy XolaElasticsearchProxyBundle: resource: "@XolaElasticsearchProxyBundle/Resources/config/routing.yml" prefix: /
The default path is /elasticsearch
and permits all HTTP methods (GET, PUT, POST, etc.).
Override it. Ensure index
(to capture elastic search index) and slug
(to capture rest of the url) remain in the
route pattern.
# app/config/routing.yml xola_elasticsearch_proxy: pattern: /myproxy/{index}/{slug} defaults: { _controller: XolaElasticsearchProxyBundle:ElasticsearchProxy:proxy } requirements: slug: ".+"
Events
There are a couple of events fired by the bundle controller that can help you. By listening to these events you can add any custom authentication or filtering logic you require.
-
elasticsearch_proxy.before_elasticsearch_request
- This event is fired before the request is sent to Elasticsearch. The listener will receiveElasticsearchProxyEvent
as an argument containing the request, index, slug, and the query object. You may modify this query object and set it back on the event withsetQuery
. The updated request will then be sent on to Elasticsearch. -
elasticsearch_proxy.after_elasticsearch_response
- This event is fired after a response has been received from Elasticsearch. The listener will receiveElasticsearchProxyEvent
as argument containing the request, index, slug, query, and response objects. You may modify the response and set it back into the event. The updated response is then sent back to the client.