Repository navigation
Elastica: support ruflin/elastica ^8.0 || ^9.0 #20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,9 +2,10 @@ | |
|
|
||
| ## Content | ||
|
|
||
| - [Setup](#usage) | ||
| - [Setup](#setup) | ||
| - [Configuration](#configuration) | ||
| - [Usage](#usage) | ||
| - [Events](#events) | ||
| - [Monolog](#monolog) | ||
|
|
||
| This extension integrates the [ruflin/elastica](https://github.com/ruflin/Elastica) into Nette Framework. | ||
|
|
@@ -15,53 +16,79 @@ For more information on how to use Elastica [read the official documentation](ht | |
| ```bash | ||
| composer require contributte/elastica | ||
| ``` | ||
| register extension | ||
|
|
||
| Elastica 8+ is built on top of [elastic/transport](https://github.com/elastic/elastic-transport-php), which needs a [PSR-18](https://www.php-fig.org/psr/psr-18/) HTTP client. | ||
| If you don't have one yet, install e.g. Guzzle (or `symfony/http-client`), it is discovered automatically. | ||
|
|
||
| ```bash | ||
| composer require guzzlehttp/guzzle | ||
| ``` | ||
|
|
||
| Register extension | ||
|
|
||
| ```neon | ||
| extensions: | ||
| elastica: Contributte\Elastica\DI\ElasticaExtension | ||
| ``` | ||
|
|
||
|
|
||
| ## Configuration | ||
|
|
||
| Define at least one host, this would be minimal possible config. | ||
|
|
||
| ```neon | ||
| elastica: | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's support multiple connections based on github.com/contributte/doctrine-dbal and github.com/contributte/doctrine-orm |
||
| config: | ||
| host: localhost | ||
| hosts: | ||
| - http://localhost:9200 | ||
| ``` | ||
|
|
||
| Full config with all possible options. | ||
|
|
||
| ```neon | ||
| elastica: | ||
| debug: %debugMode% | ||
|
|
||
| # PSR-3 logger passed to Elastica client (and elastic/transport), e.g. @monolog.logger | ||
| logger: null | ||
|
|
||
| config: | ||
| host: null | ||
| port: null | ||
| path: null | ||
| url: null | ||
| proxy: null | ||
| transport: null | ||
| compression: false | ||
| persistent: true | ||
| timeout: null | ||
| connections: [] | ||
| roundRobin: null | ||
| retryOnConflict: 0 | ||
| bigintConversion: null | ||
| hosts: [] # list of hosts, e.g. [http://es1:9200, https://user:pass@es2:9200] | ||
| cloud_id: null | ||
| api_key: null | ||
| username: null | ||
| password: null | ||
| auth_type: null | ||
| curl: [] | ||
| headers: [] | ||
| retries: null # defaults to number of hosts | ||
| retryOnConflict: 0 | ||
| transport_config: | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. snake_case -> camelCase |
||
| http_client: null # PSR-18 client service, e.g. @httpClient | ||
| http_client_config: [] # adapter config, e.g. Elastic\Elasticsearch\Transport\Adapter\AdapterOptions | ||
| http_client_options: [] # options passed to the HTTP client adapter | ||
| node_pool: null # Elastic\Transport\NodePool\NodePoolInterface service | ||
| document: | ||
| autoPopulate: false | ||
| ``` | ||
|
|
||
| Extension does not pass any unset values to elastica so elastica defaults just work. | ||
| Take a look to [Elastica docs](https://elastica-docs.readthedocs.io/en/latest/client.html#client-configurations). | ||
| Take a look to [Elastica client configuration](https://github.com/ruflin/Elastica/blob/8.x/src/ClientConfiguration.php) | ||
| and [elastic/transport](https://github.com/elastic/elastic-transport-php) docs. | ||
|
|
||
| In docker environment you should use `host: elasticsearch` and `port: 9200` for example. | ||
| In docker environment you should use `hosts: [http://elasticsearch:9200]` for example. | ||
|
|
||
| ### Upgrade from Elastica 7 | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not needed |
||
|
|
||
| Elastica 8 replaced its own connection layer with the official Elasticsearch client, so the client configuration changed | ||
| (see [UPGRADE-8.0](https://github.com/ruflin/Elastica/blob/8.x/UPGRADE-8.0.md)). | ||
|
|
||
| | Before (Elastica 7) | After (Elastica 8+) | | ||
| |---------------------------------------------|-------------------------------------------------------------------| | ||
| | `host: es.local`, `port: 9200` | `hosts: [http://es.local:9200]` | | ||
| | `url: http://es.local:9200/` | `hosts: [http://es.local:9200]` | | ||
| | `connections: [{host: a}, {host: b}]` | `hosts: [http://a:9200, http://b:9200]` | | ||
| | `roundRobin: true` | `transport_config: node_pool: @nodePool` (e.g. `SimpleNodePool` with `RoundRobin` selector) | | ||
| | `username`, `password` | unchanged (or credentials in host URL, or `api_key`) | | ||
| | `auth_type`, `transport`, `proxy`, `curl`, `compression`, `persistent`, `timeout`, `headers`, `path`, `bigintConversion` | removed, configure the PSR-18 HTTP client instead (`transport_config: http_client` / `http_client_options`) | | ||
|
|
||
| Removed options are rejected by the configuration schema, so you get a clear error after upgrade. | ||
|
|
||
| ## Usage | ||
|
|
||
|
|
@@ -80,6 +107,18 @@ class YourService | |
| } | ||
| ``` | ||
|
|
||
| ## Events | ||
|
|
||
| `Contributte\Elastica\Client` triggers `onSuccess` and `onFailure` events for every request, which are used by the Tracy panel. | ||
|
|
||
| ```php | ||
| use Elastic\Elasticsearch\Response\Elasticsearch; | ||
| use Psr\Http\Message\RequestInterface; | ||
|
|
||
| $client->onSuccess[] = function (Client $client, RequestInterface $request, Elasticsearch $response, float $time): void {}; | ||
| $client->onFailure[] = function (Client $client, RequestInterface $request, Throwable $e, float $time): void {}; | ||
| ``` | ||
|
|
||
| ## Monolog | ||
|
|
||
| You can use monolog to log errors to kibana. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,8 +19,8 @@ | |
| } | ||
| ], | ||
| "require": { | ||
| "php": ">=8.1", | ||
| "ruflin/elastica": "^7.3.1", | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Support only 9.0 |
||
| "php": ">=8.2", | ||
| "ruflin/elastica": "^8.0 || ^9.0", | ||
| "nette/di": "^3.1.8", | ||
| "nette/utils": "^4.0.3" | ||
| }, | ||
|
|
@@ -29,10 +29,15 @@ | |
| "nette/http": "^3.2.3", | ||
| "nette/bootstrap": "^3.2.1", | ||
| "mockery/mockery": "^1.6.6", | ||
| "guzzlehttp/guzzle": "^7.8", | ||
| "contributte/qa": "^0.4", | ||
| "contributte/tester": "^0.4", | ||
| "contributte/phpstan": "^0.1" | ||
| }, | ||
| "suggest": { | ||
| "guzzlehttp/guzzle": "PSR-18 HTTP client used by elastic/transport (or any other PSR-18 client, e.g. symfony/http-client)", | ||
| "tracy/tracy": "Tracy bar panel and BlueScreen panel" | ||
| }, | ||
| "conflict": { | ||
| "nette/schema": "<1.2.0" | ||
| }, | ||
|
|
@@ -56,7 +61,7 @@ | |
| }, | ||
| "extra": { | ||
| "branch-alias": { | ||
| "dev-master": "2.1.0-dev" | ||
| "dev-master": "3.0.0-dev" | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rewrite text