I have an "article" entity, that have a one to many relation with the entity "rate".
My articles are already indexed. I want to add to index the rate average for the article (calculated with the "rate" entities related to the article), and i don't know how to do this, also the average rate has to be updated if a new rate is created.
for the mapping in config.yml :
indexes:
piy:
client: default
settings:
index:
analysis:
analyzer:
custom_search_analyzer:
type: custom
tokenizer: standard
filter : [standard, lowercase, asciifolding]
custom_index_analyzer:
type: custom
tokenizer: standard
filter : [standard, lowercase, asciifolding, custom_filter]
filter:
custom_filter:
type: edgeNGram
side: front
min_gram: 1
max_gram: 20
types:
article:
mappings:
title : { search_analyzer: custom_search_analyzer, index_analyzer: custom_index_analyzer, type: string }
user:
type : object
properties :
fullName : { search_analyzer: custom_search_analyzer, index_analyzer: custom_index_analyzer, type: string }
persistence:
driver: orm
model: Piy\CoreBundle\Entity\Article
elastica_to_model_transformer:
service: piy.transformers.elastica.article
finder: ~
provider: ~
listener: ~
and for the rate entity mapping :
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\Column(type="integer", length=1)
*/
private $value;
/**
* @ORM\ManyToOne(targetEntity="Piy\CoreBundle\Entity\User", inversedBy="articleRates")
*/
public $user;
/**
* @ORM\ManyToOne(targetEntity="Piy\CoreBundle\Entity\Article", inversedBy="rates")
*/
private $article;