Skip to content

Commit d592901

Browse files
docs(elasticsearch): compatibility with laravel and improve (#2092)
1 parent 2a8a1af commit d592901

File tree

1 file changed

+30
-7
lines changed

1 file changed

+30
-7
lines changed

core/elasticsearch.md

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ To enable the reading support for Elasticsearch, simply require the Elasticsearc
1818
composer require elasticsearch/elasticsearch:^7.11
1919
```
2020

21-
Then, enable it inside the API Platform configuration:
21+
Then, enable it inside the API Platform configuration, using one of the configurations below:
22+
23+
### Enabling Reading Support using Symfony
2224

2325
```yaml
2426
# api/config/packages/api_platform.yaml
@@ -38,12 +40,32 @@ api_platform:
3840
#...
3941
```
4042

43+
### Enabling Reading Support using Laravel
44+
45+
```php
46+
<?php
47+
// config/api-platform.php
48+
return [
49+
// ....
50+
'mapping' => [
51+
'paths' => [
52+
base_path('app/Models'),
53+
],
54+
],
55+
'elasticsearch' => [
56+
'hosts' => [
57+
env('ELASTICSEARCH_HOST', 'http://localhost:9200'),
58+
],
59+
],
60+
];
61+
```
62+
4163
## Creating Models
4264

4365
API Platform follows the best practices of Elasticsearch:
4466

45-
- a single index per resource should be used because Elasticsearch is going to [drop support for index types and will allow only a single type per
46-
index](https://www.elastic.co/guide/en/elasticsearch/reference/current/removal-of-types.html);
67+
- a single index per resource should be used because Elasticsearch is going to [drop support for index types and will
68+
allow only a single type per index](https://www.elastic.co/guide/en/elasticsearch/reference/current/removal-of-types.html);
4769
- index name should be the short resource name in lower snake_case;
4870
- the default `_doc` type should be used;
4971
- all fields should be lower case and should use camelCase for combining words.
@@ -143,7 +165,7 @@ Here is an example of mappings for 2 resources, `User` and `Tweet`, and their mo
143165

144166
```php
145167
<?php
146-
// api/src/Model/User.php
168+
// api/src/Model/User.php with Symfony or app/Model/User.php with Laravel
147169
namespace App\Model;
148170

149171
use ApiPlatform\Elasticsearch\State\CollectionProvider;
@@ -182,7 +204,7 @@ class User
182204

183205
```php
184206
<?php
185-
// api/src/Model/Tweet.php
207+
// api/src/Model/Tweet.php with Symfony or app/Model/Tweet.php with Laravel
186208
namespace App\Model;
187209

188210
use ApiPlatform\Elasticsearch\State\CollectionProvider;
@@ -223,8 +245,9 @@ You're done! The API is now ready to use.
223245

224246
## Filtering
225247

226-
See how to use Elasticsearch filters and how to create Elasticsearch custom filters in [the Filters chapter](filters.md).
248+
See how to use Elasticsearch filters and how to create Elasticsearch custom filters in the
249+
[Elasticsearch filters documentation](../core/elasticsearch-filters.md).
227250

228251
## Creating Custom Extensions
229252

230-
See how to create Elasticsearch custom extensions in [the Extensions chapter](extensions.md).
253+
See how to create Elasticsearch custom extensions in [the Extensions chapter](extensions.md#custom-elasticsearch-extension).

0 commit comments

Comments
 (0)