Symfony FOSElasticaBundle:为自定义属性设置分析器
我正在使用Symfony 3.3中的FOSElasticaBundle。我已在POST_TRANSFORM事件上注册了一个事件侦听器,该事件计算如下:Symfony FOSElasticaBundle:为自定义属性设置分析器,symfony,
elasticsearch,elastica,foselasticabundle,Symfony,
elasticsearch,Elastica,Foselasticabundle,我正在使用Symfony 3.3中的FOSElasticaBundle。我已在POST_TRANSFORM事件上注册了一个事件侦听器,该事件计算如下: public function addCustomProperty(TransformEvent $event) { $document = $event->getDocument(); $custom = $this->anotherService->calculateCustom($event->get
public function addCustomProperty(TransformEvent $event)
{
$document = $event->getDocument();
$custom = $this->anotherService->calculateCustom($event->getObject());
$document->set('custom', $custom);
}
fos_elastica:
indexes:
app:
types:
myentity:
dynamic_templates:
custom_field:
path_match: customfield.*
mapping:
analyzer: myanalyzer
properties:
...
现在我需要设置用于此属性的分析器。我该怎么做
我已经尝试将自定义字段名添加到fos_elastica配置中的类型定义中,但这会导致异常,因为捆绑包随后也希望在我的实体上使用该属性。我最终发现,我可以使用
动态\u模板
设置所需的分析器,如下所示:
public function addCustomProperty(TransformEvent $event)
{
$document = $event->getDocument();
$custom = $this->anotherService->calculateCustom($event->getObject());
$document->set('custom', $custom);
}
fos_elastica:
indexes:
app:
types:
myentity:
dynamic_templates:
custom_field:
path_match: customfield.*
mapping:
analyzer: myanalyzer
properties:
...