Skip to content

Commit a38259c

Browse files
hotfix31soyuka
andauthored
reb (#2259)
Co-authored-by: soyuka <soyuka@users.noreply.github.com>
1 parent 65e5298 commit a38259c

File tree

2 files changed

+74
-13
lines changed

2 files changed

+74
-13
lines changed

core/elasticsearch-filters.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
# Elasticsearch Filters
1+
# Elasticsearch & OpenSearch Filters
2+
3+
> [!NOTE] All filters documented on this page work with both Elasticsearch and OpenSearch. See the
4+
> [Elasticsearch & OpenSearch documentation](elasticsearch.md) for setup instructions.
25
36
For further documentation on filters (including for Eloquent and Doctrine), please see the
47
[Filters documentation](filters.md).

core/elasticsearch.md

Lines changed: 70 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,26 @@
1-
# Elasticsearch Support
1+
# Elasticsearch & OpenSearch Support
22

33
## Overview
44

5-
Elasticsearch is a distributed RESTful search and analytics engine capable of solving a growing
6-
number of use cases: application search, security analytics, metrics, logging, etc.
5+
[Elasticsearch](https://www.elastic.co/elasticsearch/) and [OpenSearch](https://opensearch.org/) are
6+
distributed RESTful search and analytics engines capable of solving a growing number of use cases:
7+
application search, security analytics, metrics, logging, etc. OpenSearch is an open-source fork of
8+
Elasticsearch.
79

8-
API Platform comes natively with the **reading** support for Elasticsearch. It uses internally the
9-
official PHP client for Elasticsearch:
10-
[Elasticsearch-PHP](https://www.elastic.co/guide/en/elasticsearch/client/php-api/current/index.html).
10+
API Platform comes natively with **reading** support for both Elasticsearch and OpenSearch. It uses
11+
internally the official PHP clients:
12+
[Elasticsearch-PHP](https://www.elastic.co/guide/en/elasticsearch/client/php-api/current/index.html)
13+
or [OpenSearch-PHP](https://opensearch.org/docs/latest/clients/php/).
1114

12-
Be careful, API Platform only supports Elasticsearch >= 7.11.0 < 8.0 and Elasticsearch >= 8.4 < 9.0.
13-
Support for Elasticsearch 8 was introduced in API Platform 3.2.
15+
API Platform supports Elasticsearch >= 7.11.0 < 8.0, Elasticsearch >= 8.4 < 9.0, and OpenSearch >=
16+
2.x. Support for Elasticsearch 8 was introduced in API Platform 3.2, and OpenSearch support was
17+
introduced in API Platform 4.3.
1418

1519
## Enabling Reading Support
1620

17-
To enable the reading support for Elasticsearch, simply require the Elasticsearch-PHP package using
18-
Composer. For Elasticsearch 8:
21+
To enable the reading support, require the appropriate PHP client using Composer.
22+
23+
For Elasticsearch 8:
1924

2025
```console
2126
composer require elasticsearch/elasticsearch:^8.4
@@ -27,10 +32,18 @@ For Elasticsearch 7:
2732
composer require elasticsearch/elasticsearch:^7.11
2833
```
2934

35+
For OpenSearch:
36+
37+
```console
38+
composer require opensearch-project/opensearch-php:^2.5
39+
```
40+
3041
Then, enable it inside the API Platform configuration, using one of the configurations below:
3142

3243
### Enabling Reading Support using Symfony
3344

45+
For Elasticsearch:
46+
3447
```yaml
3548
# api/config/packages/api_platform.yaml
3649
parameters:
@@ -49,17 +62,39 @@ api_platform:
4962
#...
5063
```
5164

65+
For OpenSearch, set the `client` option to `opensearch`:
66+
67+
```yaml
68+
# api/config/packages/api_platform.yaml
69+
parameters:
70+
# ...
71+
env(OPENSEARCH_HOST): "http://localhost:9200"
72+
73+
api_platform:
74+
# ...
75+
76+
mapping:
77+
paths: ["%kernel.project_dir%/src/Model"]
78+
79+
elasticsearch:
80+
client: opensearch
81+
hosts: ["%env(OPENSEARCH_HOST)%"]
82+
83+
#...
84+
```
85+
5286
#### SSL Configuration
5387

54-
When connecting to Elasticsearch over HTTPS with self-signed certificates or custom Certificate
55-
Authorities, you can configure SSL verification.
88+
When connecting over HTTPS with self-signed certificates or custom Certificate Authorities, you can
89+
configure SSL verification. This works for both Elasticsearch and OpenSearch.
5690

5791
**With a custom CA bundle:**
5892

5993
```yaml
6094
# config/packages/api_platform.yaml
6195
api_platform:
6296
elasticsearch:
97+
<<<<<<< HEAD
6398
hosts: ["%env(ELASTICSEARCH_HOST)%"]
6499
ssl_ca_bundle: "/path/to/ca-bundle.crt"
65100
```
@@ -78,6 +113,8 @@ api_platform:
78113
79114
### Enabling Reading Support using Laravel
80115
116+
For Elasticsearch:
117+
81118
```php
82119
<?php
83120
// config/api-platform.php
@@ -96,6 +133,27 @@ return [
96133
];
97134
```
98135

136+
For OpenSearch:
137+
138+
```php
139+
<?php
140+
// config/api-platform.php
141+
return [
142+
// ....
143+
'mapping' => [
144+
'paths' => [
145+
base_path('app/Models'),
146+
],
147+
],
148+
'elasticsearch' => [
149+
'client' => 'opensearch',
150+
'hosts' => [
151+
env('OPENSEARCH_HOST', 'http://localhost:9200'),
152+
],
153+
],
154+
];
155+
```
156+
99157
## Creating Models
100158

101159
API Platform follows the best practices of Elasticsearch:

0 commit comments

Comments
 (0)