@@ -18,7 +18,9 @@ To enable the reading support for Elasticsearch, simply require the Elasticsearc
18
18
composer require elasticsearch/elasticsearch:^7.11
19
19
```
20
20
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
22
24
23
25
``` yaml
24
26
# api/config/packages/api_platform.yaml
@@ -38,12 +40,32 @@ api_platform:
38
40
# ...
39
41
```
40
42
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
+
41
63
## Creating Models
42
64
43
65
API Platform follows the best practices of Elasticsearch:
44
66
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 ) ;
47
69
- index name should be the short resource name in lower snake_case;
48
70
- the default ` _doc ` type should be used;
49
71
- 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
143
165
144
166
``` php
145
167
<?php
146
- // api/src/Model/User.php
168
+ // api/src/Model/User.php with Symfony or app/Model/User.php with Laravel
147
169
namespace App\Model;
148
170
149
171
use ApiPlatform\Elasticsearch\State\CollectionProvider;
@@ -182,7 +204,7 @@ class User
182
204
183
205
``` php
184
206
<?php
185
- // api/src/Model/Tweet.php
207
+ // api/src/Model/Tweet.php with Symfony or app/Model/Tweet.php with Laravel
186
208
namespace App\Model;
187
209
188
210
use ApiPlatform\Elasticsearch\State\CollectionProvider;
@@ -223,8 +245,9 @@ You're done! The API is now ready to use.
223
245
224
246
## Filtering
225
247
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 ) .
227
250
228
251
## Creating Custom Extensions
229
252
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