You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Resources/doc/crud.md
+31-61Lines changed: 31 additions & 61 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,75 +5,52 @@
5
5
For all steps below we assume that there is an `AppBundle` with the `Content` document.
6
6
7
7
```php
8
-
// src/AppBundle/Document/Content.php
8
+
// src/Document/Product.php
9
9
10
-
namespace AppBundle\Document;
10
+
namespace App\Document;
11
11
12
12
use ONGR\ElasticsearchBundle\Annotation as ES;
13
13
14
14
/**
15
-
* @ES\Document(type="content")
15
+
* //alias and default parameters in the annotation are optional.
16
+
* @ES\Index(alias="content", default=true)
16
17
*/
17
18
class Content
18
19
{
19
20
/**
20
-
* @var string
21
-
*
22
21
* @ES\Id()
23
22
*/
24
23
public $id;
25
24
26
25
/**
27
-
* @ES\Property(type="keyword")
26
+
* @ES\Property(type="text")
28
27
*/
29
28
public $title;
30
29
}
31
30
```
32
31
33
-
## Manager
34
-
35
-
Elasticsearch bundle provides managers able to handle several indexes to communicate with elasticsearch.
36
-
37
-
Once you define managers in your `config.yml` file, you can use them in controllers and grab them from DI container via `es.manager` (alias for `es.manager.default`). If you define more than one manager, for example called `foo`, then it will be accessible via `es.manager.foo`.
38
-
39
-
```php
40
-
41
-
$manager = $this->get('es.manager');
42
-
43
-
```
32
+
> Important notice: you don't need your properties to be public, but they will
33
+
>need to have getters and setters otherwise.
44
34
45
-
## Repositories
46
-
47
-
In addition manager provides repository access, which enables direct access to the elasticsearch type.
48
-
Repository represents a document. Whenever you need to do any action with a repository, you can access
@@ -106,8 +83,8 @@ To update a field you need to know the document `ID` and fields to update. Here'
106
83
107
84
```php
108
85
109
-
$repo = $this->get('es.manager.default.content');
110
-
$repo->update(1, ['title' => 'new title']);
86
+
$index = $this->get(Content::class);
87
+
$index->update(1, ['title' => 'new title']);
111
88
112
89
```
113
90
@@ -116,22 +93,23 @@ You can also update fields with script operation, lets say, you want to do some
116
93
117
94
```php
118
95
119
-
$repo = $this->get('es.manager.default.product');
120
-
$repo->update(1, [], 'ctx._source.stock+=1');
96
+
$index = $this->get(Content::class);
97
+
$index->update(1, [], 'ctx._source.stock+=1');
121
98
122
99
```
123
100
> Important: when using script update fields cannot be updated, leave empty array, otherwise you will get 400 exception.
124
101
125
102
`ctx._source` comes from groovy scripting and you have to enable it in elasticsearch config with: `script.groovy.sandbox.enabled: false`
126
103
127
104
128
-
In addition you also can get other document fields with the response of update, lets say we also want a content field and a new title, so just add them separated by a comma:
105
+
In addition you also can get other document fields with the response of update,
106
+
lets say we also want a content field and a new title, so just add them separated by a comma:
0 commit comments