Skip to content

Commit 23acabc

Browse files
author
Mantas Marcinkevicius
committed
updated the docs
1 parent 8fa6959 commit 23acabc

File tree

3 files changed

+77
-110
lines changed

3 files changed

+77
-110
lines changed

README.md

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -71,17 +71,13 @@ php composer.phar require ongr/elasticsearch-bundle "~6.0"
7171
Enable ElasticSearch bundle in your AppKernel:
7272

7373
```php
74-
// app/AppKernel.php
74+
<?php
75+
// config/bundles.php
7576

76-
public function registerBundles()
77-
{
78-
$bundles = [
79-
// ...
80-
new ONGR\ElasticsearchBundle\ONGRElasticsearchBundle(),
81-
];
82-
77+
return [
8378
// ...
84-
}
79+
ONGR\ElasticsearchBundle\ONGRElasticsearchBundle::class => ['all' => true],
80+
];
8581

8682
```
8783

@@ -91,7 +87,7 @@ Add minimal configuration for Elasticsearch bundle.
9187

9288
```yaml
9389

94-
# app/config/config.yml
90+
# config/packages/ongr_elasticsearch.yaml
9591
ongr_elasticsearch:
9692
analysis:
9793
filter:
@@ -106,6 +102,9 @@ ongr_elasticsearch:
106102
filter:
107103
- lowercase
108104
- edge_ngram_filter #that's the filter defined earlier
105+
indexes:
106+
App\Document\Product:
107+
hosts: [elasticsearch:9200] # optional, the default is 127.0.0.1:9200
109108

110109
```
111110

@@ -116,15 +115,15 @@ ongr_elasticsearch:
116115
This bundle uses objects to represent Elasticsearch documents. Lets create the `Product` class for the `products` index.
117116

118117
```php
119-
// src/AppBundle/Document/Customer.php
118+
// src/Document/Product.php
120119

121-
namespace AppBundle\Document;
120+
namespace App\Document;
122121

123122
use ONGR\ElasticsearchBundle\Annotation as ES;
124123

125124
/**
126125
* //alias and default parameters in the annotation are optional.
127-
* @ES\Document(alias="products", default=true)
126+
* @ES\Index(alias="products", default=true)
128127
*/
129128
class Product
130129
{
@@ -169,6 +168,11 @@ Now the `products` index should be created with fields from your document.
169168
Full documentation for the Elasticsearch bundle is [available here][4].
170169
I hope you will create amazing things with it :sunglasses: .
171170

171+
> Please note that the updating process of the documentation of the bundle to 6.0
172+
>is still under way. Read the [configuration][7] and [crud][9] sections that are
173+
>already updated and will allow you to have the basic functions of the bundle. We
174+
>will update the rest of the documentation as soon as possible
175+
172176
## Troubleshooting
173177
* [How to upgrade from the older versions?][15]
174178
* [How to overwrite some parts of the bundle?][16]
@@ -194,3 +198,4 @@ in the bundle `LICENSE` file.
194198
[14]: https://www.elastic.co/downloads/elasticsearch
195199
[15]: http://docs.ongr.io/ElasticsearchBundle/upgrade
196200
[16]: http://docs.ongr.io/ElasticsearchBundle/overwriting_bundle
201+

Resources/doc/configuration.md

Lines changed: 28 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -5,40 +5,32 @@ Here's an example of full configuration with all possible options including defa
55
```yml
66
ongr_elasticsearch:
77
analysis:
8-
analyzer:
9-
pathAnalyzer:
10-
type: custom
11-
tokenizer: pathTokenizer
12-
tokenizer:
13-
pathTokenizer:
14-
type : path_hierarchy
15-
buffer_size: 2024
16-
skip: 0
17-
delimiter: /
18-
filter:
19-
incremental_filter:
20-
type: edge_ngram
21-
min_gram: 1
22-
max_gram: 20
23-
managers:
24-
default:
25-
index:
26-
hosts:
27-
- 127.0.0.1:9200
28-
index_name: ongr-default
29-
settings:
30-
refresh_interval: -1
31-
number_of_replicas: 0
32-
number_of_shards: 1
33-
logger: true #default %kernel.debug%
34-
mappings:
35-
- AcmeBarBundle #Scans all bundle documents
36-
custom:
37-
index:
38-
hosts:
39-
- 10.0.0.1:9200 #default 127.0.0.1:9200
40-
index_name: ongr-custom
41-
mappings:
42-
AcmeBundle:
43-
document_dir: Document
8+
analyzer:
9+
pathAnalyzer:
10+
type: custom
11+
tokenizer: pathTokenizer
12+
tokenizer:
13+
pathTokenizer:
14+
type : path_hierarchy
15+
buffer_size: 2024
16+
skip: 0
17+
delimiter: /
18+
filter:
19+
incremental_filter:
20+
type: edge_ngram
21+
min_gram: 1
22+
max_gram: 20
23+
source_directory: /src/AppBundle
24+
logger: false
25+
profiler: true
26+
cache: true
27+
indexes: # overrides any index related config from anotations
28+
App\Document\Page:
29+
default: true
30+
hosts:
31+
- 'elasticsearch:9200'
32+
settings:
33+
number_of_replicas: 2
34+
number_of_shards: 3
35+
type: page # for 5.x ES compatibility
4436
```

Resources/doc/crud.md

Lines changed: 31 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -5,75 +5,52 @@
55
For all steps below we assume that there is an `AppBundle` with the `Content` document.
66

77
```php
8-
// src/AppBundle/Document/Content.php
8+
// src/Document/Product.php
99

10-
namespace AppBundle\Document;
10+
namespace App\Document;
1111

1212
use ONGR\ElasticsearchBundle\Annotation as ES;
1313

1414
/**
15-
* @ES\Document(type="content")
15+
* //alias and default parameters in the annotation are optional.
16+
* @ES\Index(alias="content", default=true)
1617
*/
1718
class Content
1819
{
1920
/**
20-
* @var string
21-
*
2221
* @ES\Id()
2322
*/
2423
public $id;
2524

2625
/**
27-
* @ES\Property(type="keyword")
26+
* @ES\Property(type="text")
2827
*/
2928
public $title;
3029
}
3130
```
3231

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.
4434
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
49-
it like this:
50-
51-
```php
52-
53-
$manager = $this->get('es.manager');
54-
$repo = $manager->getRepository('AppBundle:Content');
35+
## Manager
5536

56-
```
37+
Elasticsearch bundle provides managers called indexes to able to handle several ES indexes
38+
for communication with elasticsearch.
5739

58-
Alternatively:
40+
Each index will have its dedicated manager that can be reached via service container by the
41+
name of the namespace of the Document class that represents the index in question. So in our
42+
case:
5943

6044
```php
6145

62-
$repo = $this->get('es.manager.default.content');
46+
$index = $container->get(Content::class);
6347

6448
```
6549

66-
`default` - represents a manager name and `content` an elasticsearch type name.
50+
> Important: The old implementation was to have manager and repositories dedicated
51+
>for each document type. In 6.0 the functionalities of these services were merged
52+
>into the index service for each document.
6753
68-
> Important: Document with the certain type name has to be mapped in the manager.
69-
70-
You can also get a manager from the repo instance:
71-
72-
```php
73-
74-
$manager = $repo->getManager();
75-
76-
```
7754

7855
## Create a document
7956

@@ -82,19 +59,19 @@ $manager = $repo->getManager();
8259
$content = new Content();
8360
$content->id = 5; // Optional, if not set, elasticsearch will set a random.
8461
$content->title = 'Acme title';
85-
$manager->persist($content);
86-
$manager->commit();
62+
$index->persist($content);
63+
$index->commit();
8764

8865
```
8966

9067
## Update a document
9168

9269
```php
9370

94-
$content = $manager->find('AppBundle:Content', 5);
71+
$content = $index->find(5); // Alternatively $index->findBy(['title' => 'acme title']);
9572
$content->title = 'changed Acme title';
96-
$manager->persist($content);
97-
$manager->commit();
73+
$index->persist($content);
74+
$index->commit();
9875

9976
```
10077

@@ -106,8 +83,8 @@ To update a field you need to know the document `ID` and fields to update. Here'
10683

10784
```php
10885

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']);
11188

11289
```
11390

@@ -116,22 +93,23 @@ You can also update fields with script operation, lets say, you want to do some
11693

11794
```php
11895

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');
12198

12299
```
123100
> Important: when using script update fields cannot be updated, leave empty array, otherwise you will get 400 exception.
124101
125102
`ctx._source` comes from groovy scripting and you have to enable it in elasticsearch config with: `script.groovy.sandbox.enabled: false`
126103

127104

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:
129107

130108

131109
```php
132110

133-
$repo = $this->get('es.manager.default.content');
134-
$response = $repo->update(1, ['title' => 'new title'], null, ['fields' => 'title,content']);
111+
$index = $this->get(Content::class);
112+
$index = $repo->update(1, ['title' => 'new title'], null, ['fields' => 'title,content']);
135113

136114
```
137115

@@ -141,15 +119,7 @@ $response = $repo->update(1, ['title' => 'new title'], null, ['fields' => 'title
141119
Document removal can be performed similarly to create or update action:
142120

143121
```php
144-
$manager->remove($content);
145-
$manager->commit();
146-
```
147-
148-
Alternatively you can remove document by ID (requires to have repository service):
149-
150-
```php
151-
152122
$repo = $this->get('es.manager.default.content');
153123
$content = $repo->remove(5);
154-
155124
```
125+

0 commit comments

Comments
 (0)