diff --git a/Annotation/Version.php b/Annotation/Version.php new file mode 100644 index 00000000..60d00c3a --- /dev/null +++ b/Annotation/Version.php @@ -0,0 +1,37 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace ONGR\ElasticsearchBundle\Annotation; + +/** + * Associates document property with _version meta-field. + * + * @Annotation + * @Target("PROPERTY") + */ +final class Version implements MetaField +{ + /** + * {@inheritdoc} + */ + public function getName() + { + return '_version'; + } + + /** + * {@inheritdoc} + */ + public function getSettings() + { + return []; + } +} diff --git a/Mapping/DocumentParser.php b/Mapping/DocumentParser.php index d73bae70..d80f5e6b 100644 --- a/Mapping/DocumentParser.php +++ b/Mapping/DocumentParser.php @@ -37,6 +37,7 @@ class DocumentParser const PARENT_ANNOTATION = 'ONGR\ElasticsearchBundle\Annotation\ParentDocument'; const TTL_ANNOTATION = 'ONGR\ElasticsearchBundle\Annotation\Ttl'; const ROUTING_ANNOTATION = 'ONGR\ElasticsearchBundle\Annotation\Routing'; + const VERSION_ANNOTATION = 'ONGR\ElasticsearchBundle\Annotation\Version'; /** * @var Reader Used to read document annotations. @@ -177,6 +178,7 @@ private function getMetaFieldAnnotationData($property) $annotation = $annotation ?: $this->reader->getPropertyAnnotation($property, self::PARENT_ANNOTATION); $annotation = $annotation ?: $this->reader->getPropertyAnnotation($property, self::TTL_ANNOTATION); $annotation = $annotation ?: $this->reader->getPropertyAnnotation($property, self::ROUTING_ANNOTATION); + $annotation = $annotation ?: $this->reader->getPropertyAnnotation($property, self::VERSION_ANNOTATION); if ($annotation === null) { return null; @@ -358,6 +360,7 @@ private function registerAnnotations() 'ParentDocument', 'Ttl', 'Routing', + 'Version', ]; foreach ($annotations as $annotation) {