Skip to content

Commit 28a1229

Browse files
einorlersaimaz
authored andcommitted
Updated Documentation for v5.x (#762)
* updated the changelog * updated the mapping docs * added docs on routing annotation: * updated crud chapter * updated search documentation * updated the scan documentation * updated the upgrade documentation * updated docs for results parsing * updated overwriting section
1 parent d149a9b commit 28a1229

File tree

9 files changed

+120
-63
lines changed

9 files changed

+120
-63
lines changed

CHANGELOG.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,31 @@
55
- Array iterator now returns document _id field as well.
66
- Document annotation now has an options support.
77
You can pass any settings along parameters you want. Simply just put them in the options.
8+
- `Manager::getSettings()` was added. Returns the currently configured settings for manager index.
9+
- `Manager::getAliases()` was added. Gets Elasticsearch aliases information.
810
- Added `text` and `keyword` property types support.
11+
- Added `murmur3`, `attachments`, `percolator` property type support
12+
- Added `hash_map` annotation. #747
13+
- Added `ONGR\ElasticsearchBundle\Exception` namespace.
914
- Added `char_filter` analysis support.
1015
- All features and fixes from 1.2.x
1116
- Added `document_dir`. From now on you can change documents directory for each mapped bundle.
1217
- No more needed to define analysis in manager, it will be collected automatically from documents.
1318

1419
### Breaking changes
1520
- Removed all deprecations from 1.x version.
21+
- Removed `_ttl` metafield annotation.
1622
- Service name `@annotations.cached_reader` changed to `@es.annotations.cached_reader` #717
1723
- From Document annotation removed all properties except `type`. From now on everything has to be defined in the `options`.
18-
- `string` property type was deprecated in elasticsearch 5.0, please use text or keyword accordingly.
24+
- `string` property type was deprecated in elasticsearch 5.0, please use `text` or `keyword` accordingly.
1925
More info: https://www.elastic.co/blog/strings-are-dead-long-live-strings
2026
- `auth` in the configuration was removed. Use authentication information directly in host or create event listener
2127
to modify client creation. There are too many ways to authenticate elasticsearch. That said we leaving this customisation to the user due difficult support.
2228
- `connections` node in configuration was removed. Use `index` from now on. There was absolute
2329
misunderstanding to have exposed connections, we never saw any benefits to use single connection
2430
between several managers.
25-
- `analysis` node in `index`/`connection` was deprecated. From now on used analyzers, filters and other
31+
- Changed the namespace of the `DocumentParserException` to `ONGR\ElasticsearchBundle\Mapping\Exception`. #722
32+
- `analysis` node in `index`/`connection` was deprecated. From now on used analyzers, filters, etc. must be provided in document annotations
2633
- `Results` (constants container for result type definitions) class was removed in favor for
2734
new find functions with predefined types in the names.
2835
- Export service now uses own query calling instead of elasticsearch-php. It was changes due a bug

Resources/doc/crud.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class Content
2424
public $id;
2525

2626
/**
27-
* @ES\Property(type="string")
27+
* @ES\Property(type="keyword")
2828
*/
2929
public $title;
3030
}
@@ -44,7 +44,9 @@ $manager = $this->get('es.manager');
4444

4545
## Repositories
4646

47-
In addition manager provides repository access, which enables direct access to the elasticsearch type. Repositories represents a document. Whenever you need to do any action with a repository to get it:
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:
4850

4951
```php
5052

@@ -53,7 +55,7 @@ $repo = $manager->getRepository('AppBundle:Content');
5355

5456
```
5557

56-
So instead you can call just:
58+
Alternatively:
5759

5860
```php
5961

Resources/doc/mapping.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -178,14 +178,14 @@ class Product
178178
}
179179
```
180180

181-
> There is no mandatory to have private properties, and public will work as well.
182-
We are firmly recommend using private according to OOP best practices.
181+
> It is not mandatory to have private properties, and public will work as well.
182+
However, we firmly recommend using private according to OOP best practices.
183183

184184
#### Document annotation configuration
185185

186186
- `@ES\Document(type="product")` Annotation defines that this class will represent elasticsearch type with name `content`.
187-
- You can append any options from elasticsearch type options in `options` variable.
188-
E.g. you want to add `enable:false` so it will look like: `@ES\Document(type="product", options={"enable":"false"})`
187+
- You can append any valid elasticsearch type options to the `options` variable.
188+
E.g. if you want to add `enable:false` it will look like this: `@ES\Document(type="product", options={"enable":"false"})`
189189
- `type` parameter is for type name. This parameter is optional, if there will be no parameter set,
190190
ElasticsearchBundle will create a type with lower cased class name.
191191

@@ -194,13 +194,13 @@ ElasticsearchBundle will create a type with lower cased class name.
194194

195195
For defining type properties, there is a `@ES\Property` annotation. The only required
196196
attribute is `type` - Elasticsearch field type to specify what kind of information
197-
will be indexed. By default, the field name generated from property name by converting
198-
it to "snake case" string. You can specify the custom name by setting `name` attribute.
197+
will be indexed. By default, the field name is generated from property name by converting
198+
it to "snake case" string. You can specify a custom name by setting the `name` attribute.
199199

200200
> Read more about elasticsearch supported types [in the official documentation][2].
201201

202202
To add a custom setting for the property like analyzer include it in the `options` variable.
203-
Analyzers names defined in `config.yml` `analysis` [read more in the topic above](#Mapping configuration).
203+
Analyzers names must be defined in `config.yml` under the `analysis` node (read more in the topic above).
204204
Here's an example how to add it:
205205

206206
```php
@@ -289,7 +289,7 @@ class CategoryObject
289289
290290
```
291291

292-
> Class name can be anything, we called it `CategoryObject` to make it more readable and notice that is an object.
292+
> Class name can be anything, we called it `CategoryObject` to make it more readable. Notice that it is an object, not a document.
293293

294294
For this particular example the mapping in elasticsearch will look like this:
295295

@@ -317,7 +317,7 @@ For this particular example the mapping in elasticsearch will look like this:
317317

318318
To insert a document with mapping from example above you have to create 2 objects:
319319

320-
```php
320+
```php
321321
322322
$category = new CategoryObject();
323323
$category->setTitle('Jeans');
@@ -330,11 +330,11 @@ To insert a document with mapping from example above you have to create 2 object
330330
$manager->persist($product);
331331
$manager->commit();
332332
333-
```
333+
```
334334

335335
##### Multiple objects
336336

337-
As shown in the example above, by ElasticsearchBundle default only a single object will be saved in the document.
337+
As shown in the example above, by ElasticsearchBundle default, only a single object will be saved in the document.
338338
Meanwhile, Elasticsearch database doesn't care if in an object is stored as a single value or as an array.
339339
If it is necessary to store multiple objects (array), you have to add `multiple=true` to the annotation. While
340340
initiating a document with multiple items you need to initialize property with the new instance of `Collection()`.
@@ -347,6 +347,7 @@ Here's an example:
347347
namespace AppBundle\Document;
348348
349349
use ONGR\ElasticsearchBundle\Annotation as ES;
350+
use ONGR\ElasticsearchBundle\Collection\Collection;
350351
351352
/**
352353
* @ES\Document()
@@ -396,7 +397,6 @@ And the object:
396397
namespace AppBundle\Document;
397398
398399
use ONGR\ElasticsearchBundle\Annotation as ES;
399-
use ONGR\ElasticsearchBundle\Collection\Collection;
400400
401401
/**
402402
* @ES\Object
@@ -512,7 +512,7 @@ look like this:
512512

513513
### Meta-Fields Annotations
514514

515-
There are other meta field for different behaviours of elasticsearch.
515+
There are specialized meta fields that introduce different behaviours of elasticsearch.
516516
Read the dedicated page about meta-field annotations [here](http://docs.ongr.io/ElasticsearchBundle/meta_fields).
517517

518518
> More information about mapping can be found in the [Elasticsearch mapping documentation][3].

Resources/doc/meta_fields.md

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -47,32 +47,25 @@ attribute is `class`, where you need to specify class of parent document.
4747
public $parent;
4848
```
4949

50-
### @Ttl (_ttl)
50+
### @Routing (_routing)
5151

52-
This field allows to configure how long a document should live before it is automatically
53-
deleted. After you add property with `@Ttl` annotation, TTL feature is automatically enabled.
52+
Custom routing patterns can be implemented by specifying a custom routing value per document.
53+
The same routing value needs to be provided when getting, deleting, or updating the document.
54+
It is represented by the `@Routing` annotation. Here is an example of such a field:
5455

5556
```php
5657
/**
57-
* @ES\Ttl()
58+
* @ES\Routing()
5859
*/
59-
public $ttl;
60+
public $routing;
6061
```
6162

62-
You can set default TTL with optional `default` attribute:
63+
Forgetting the routing value can lead to a document being indexed on more than one shard.
64+
As a safeguard, the _routing field can be configured to make a custom routing value
65+
required for all CRUD operations. This can be implemented by setting the `equired`
66+
attribute to true (`@ES\Routing(required=true)`).
6367

64-
```php
65-
/**
66-
* @ES\Ttl(default="5m")
67-
*/
68-
public $ttl;
69-
```
70-
71-
Example above sets default TTL to 5 minutes. See Elasticsearch [documentation][2]
72-
for supported time value formats.
73-
74-
> __Note:__ The current `_ttl` implementation is deprecated by Elasticsearch and
75-
> might be replaced with a different implementation in a future version.
68+
More information on routing can be found in the [dedicated docs][2]
7669

7770
[1]: https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-fields.html
78-
[2]: https://www.elastic.co/guide/en/elasticsearch/reference/current/common-options.html#time-units
71+
[2]: https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-routing-field.html
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# Overwriting bundle parts
22

3-
Will come with v1.1.0 version. Check [milestones](https://github.com/ongr-io/ElasticsearchBundle/milestones) to see a progress with the new versions releases.
3+
Documentation in progress...

Resources/doc/results_parsing.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ For all chapters below we will use a data example inserted in the elasticsearch
2424

2525
## Results iterator
2626

27-
Whenever any search action is performed and `Result::RESULTS_OBJECT` is selected as the result type the `DocumentIterator` will be returned. It has plenty of helper functions to aggregate more efficiently with the results.
27+
Usually when any search action is performed the `DocumentIterator` will be returned. It has plenty of helper functions to aggregate more efficiently with the results.
2828

2929

3030
Lets assume you search the index with:
@@ -34,7 +34,7 @@ Lets assume you search the index with:
3434
$repo = $this->get('es.manager.default.content');
3535
$search = $repo->createSearch();
3636
$termQuery = new MatchAllQuery();
37-
$results = $repo->execute($search, Result::RESULTS_OBJECT); // Result::RESULTS_OBJECT is the default value
37+
$results = $repo->findDocuments($search);
3838

3939
```
4040

@@ -68,7 +68,7 @@ cannot be associated with document. You can get document's score from results it
6868
while iterating:
6969

7070
```php
71-
$results = $repository->execute($search);
71+
$results = $repository->findDocuments($search);
7272

7373
foreach ($results as $document) {
7474
echo $document->title, $results->getDocumentScore();
@@ -95,9 +95,9 @@ foreach ($results as $document) {
9595

9696
`DocumentIterator` doesn't cache or store generated document object. `Converter` directly returns the instance after it's requested and will generate again if it will be requested.
9797

98-
We highly recommend to `unset()` document instance after you dont need it or manage memory at your own way.
98+
We highly recommend to `unset()` document instance after you don't need it or manage memory at your own way.
9999

100-
There is a possibility to change the `DocumentIterator` behaviour. Take a look at the [overwriting bundle parts](overwriting_bundle.md).
100+
There is a possibility to change the `DocumentIterator` behaviour. Take a look at the [overwriting bundle parts](http://docs.ongr.io/ElasticsearchBundle/overwriting_bundle).
101101

102102
## Aggregations
103103

@@ -118,7 +118,7 @@ $brandTermAggregation->addAggregation($avgPriceAggregation);
118118
$query = new Search();
119119
$query->addAggregation($brandTermAggregation);
120120

121-
$result = $this->get('es.manager')->execute(['AppBundle:Product'], $query);
121+
$result = $this->get('es.manager.default.content')->findDocuments($query);
122122

123123
// Build a list of available choices
124124
$choices = [];

Resources/doc/scan.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ If the index is huge and in a single request there is not enough to get all reco
44

55
> More info about index scanning in [elastic official docs](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-scroll.html#scroll-scan)
66
7-
You can scan index with any structured search and do a continious scroll. To execute that kind of search you only need to append a scroll time amount to a `Search` object.
7+
You can scan index with any structured search and do a continuous scroll. To execute that kind of search you only need to append a scroll time amount to a `Search` object.
88

9-
> Scan & Scroll doesn't work if the result type is `Repository:RESULTS_ARRAY`.
9+
> Scan & Scroll doesn't work for `Repository::findArray()` method.
1010
1111
Here's an example with scrolling:
1212

@@ -20,7 +20,7 @@ $search->setScroll('10m'); // Scroll time
2020
$termQuery = new TermQuery('country', 'Lithuania');
2121
$search->addQuery($termQuery);
2222

23-
$results = $repo->execute($search);
23+
$results = $repo->findDocuments($search);
2424

2525
foreach ($results as $document) {
2626

@@ -32,7 +32,7 @@ foreach ($results as $document) {
3232

3333
Usually result amount will be 10 (if no size set), but if the result type is any iterator, it will do a next request when the results set limit is reached and will continue results scrolling in foreach cycle. You dont have to worry about any scroll ids and how to perform second request, everything is handled automatically.
3434

35-
If you are using `Repository:RESULTS_RAW`, then bundle won't request next iteration and you should do it by yourself. Here's an example how to do it:
35+
If you are using `findRaw()` method, then bundle won't request next iteration and you should do it by yourself. Here's an example how to do it:
3636

3737

3838
```php
@@ -45,14 +45,14 @@ $search->setScroll('10m'); // Scroll time
4545
$termQuery = new TermQuery('country', 'Lithuania');
4646
$search->addQuery($termQuery);
4747

48-
$results = $repo->execute($search, Result::RESULTS_RAW);
48+
$results = $repo->findRaw($search);
4949

5050
foreach ($results as $raw) {
5151

5252
// Do something with RAW results
5353

5454
}
5555

56-
$nextIteration = $repo->getManager()->scroll($results['_scroll_id'], '10m', Result::RESULTS_RAW);
56+
$nextIteration = $repo->getManager()->scroll($results['_scroll_id'], '10m');
5757

5858
```

Resources/doc/search.md

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,24 @@
22

33
## Structured search with DSL
44

5-
If find functions are not enough, there is a possibility to perform a structured search using [query builder](https://github.com/ongr-io/ElasticsearchDSL). In a nutshell you can do any query or filter that is defined in [Elasticsearch Query DSL documentation](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl.html).
5+
If find functions are not enough, there is a possibility to perform a structured search using [query builder](https://github.com/ongr-io/ElasticsearchDSL). In a nutshell you can construct any queries, aggregations, etc. that are defined in [Elasticsearch Query DSL documentation](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl.html).
66

7-
To begin with structured search you will need a `Search` object.
7+
To begin with structured search you will need a `Search` object. You need to add all the queries and other DSL constructs
8+
to this search object and then perform the search from the repository service. There are three specialized `find` methods
9+
dedicated for this task and you may choose between depending on your needs:
810

9-
e.g. We want to search for cities in Lithuania with more than 10K population
11+
| method | Return Type |
12+
|:-----------------:|:-------------------------------------------------------------------------------:|
13+
| `findDocuments()` | Returns an instance of `DocumentIterator` |
14+
| `findArray()` | Returns an instance of `ArrayIterator` |
15+
| `findRaw()` | Returns an array of raw results with unaltered elasticsearch response structure |
16+
17+
For the majority of cases, you will be using `findDocuments` that returns an iterator with hydrated documents. In addition
18+
it provides a convenient way of handling aggregations, that can be accessed via `getAggregations()` method.
19+
20+
### Simple Example
21+
22+
In this example we will search for cities in Lithuania with more than 10K population
1023

1124
```php
1225

@@ -19,7 +32,7 @@ $search->addQuery($termQuery);
1932
$rangeQuery = new RangeQuery('population', ['from' => 10000]);
2033
$search->addQuery($rangeQuery);
2134

22-
$results = $repo->execute($search);
35+
$results = $repo->findDocuments($search);
2336

2437
```
2538

@@ -54,7 +67,8 @@ It will construct a query:
5467

5568
> Important: by default result size in elasticsearch is 10, if you need more set size to your needs.
5669
57-
Setting size or offset is to the search is very easy, because it has getters and setters for these attributes. Therefore to set size all you need to do is to write
70+
Setting size or offset is to the search is very easy, because it has getters and setters for these attributes.
71+
Therefore to set size all you need to do is to write
5872

5973
```php
6074

@@ -66,14 +80,17 @@ Similarly other properties like Scroll, Timeout, MinScore and more can be define
6680

6781
For more query and filter examples take a look at the [Elasticsearch DSL library docs](https://github.com/ongr-io/ElasticsearchDSL/blob/master/docs/index.md). We covered all examples that we found in [Elasticsearch Query DSL documentation](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl.html) how to cover in object oriented way.
6882

69-
> The results parsing is the same like in the find functions.
70-
7183
## Searching in Multiple Types
7284

73-
Previous section showed how to search in single type using repository. In some
74-
cases you might need to search multiple types at once. In order to do that you
75-
can use manager's `execute()` method (actually repository's `execute()` is just
76-
a proxy for this method).
85+
Previous example illustrated the usual case scenario of performing a search in a single type.
86+
However if you should ever find yourself in a rear situation where a search needs to be performed
87+
on several types at once, you can use a specific `search` method in manager, that accepts an
88+
array with the names of types on which the search needs to be performed.
89+
90+
However, unlike some of the `find` functions in repository this method returns only the raw results,
91+
therefore the use of this method should be minimal and only when needed.
92+
93+
### Example of searching in multiple types
7794

7895
Lets say you have `City` and `State` documents with `title` field. Search all
7996
cities and states with title "Indiana":
@@ -85,11 +102,11 @@ $search->addQuery(new TermQuery('title', 'Indiana'));
85102
$results = $manager->execute(
86103
// Array of documents representing different types
87104
['AppBundle:City', 'AppBundle:State'],
88-
$search
105+
$search->toArray()
89106
);
90107
```
91108

92-
This example returns an iterator with all matching documents.
109+
> Notice, that the second argument needs to be an array, not a `Search` instance.
93110
94111
## Results count
95112

0 commit comments

Comments
 (0)