Skip to content

Commit

Permalink
Fixed tests and docs about problem in getting _parent with ES 1.x
Browse files Browse the repository at this point in the history
  • Loading branch information
pmishev committed Jul 11, 2016
1 parent d6c3e6a commit 75c86f1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Resources/doc/mapping.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ class Answer
```
> Do not forget to also set the `parent` property of the `@ES\Document` annotation to specify the parent entity for that type.
**WARNING**: If using Elasticsearch 1.x, the parent property value will NOT be populated when retrieving documents, as Elasticsearch does not return it by default!

## Object class annotation

Object classes are almost the same as document classes:
Expand Down
9 changes: 8 additions & 1 deletion Tests/Functional/Mapping/MetaFieldsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ protected function setUp()
public function testCreateChildDocument()
{
$im = $this->getIndexManager('qanda');
$esVersion = $im->getConnection()->getClient()->info()['version']['number'];

$answer = new Answer();
$answer->id = 'NEWID';
Expand Down Expand Up @@ -95,7 +96,13 @@ public function testCreateChildDocument()
/** @var Answer $doc */
$doc = $res->current();

$this->assertEquals('2', $doc->parentId, 'Parent document id is wrong');
if (version_compare($esVersion, '2.0', '>=')) {
$this->assertEquals('2', $doc->parentId, 'Parent document id is wrong');
} else {
// In ES versions before 2.0, _parent is not returned by default and thus not populated in the entity
// @see https://github.com/elastic/elasticsearch/issues/8068
$this->assertEquals(null, $doc->parentId, 'Parent document id is wrong');
}
}

public function testParentChildSearch()
Expand Down

0 comments on commit 75c86f1

Please sign in to comment.