我目前正在尝试使用FOSElastica,但配置遇到问题。我想对大多数实体使用序列化程序,但是我想为特定实体指定映射,我该怎么做?
我尝试定义“属性”选项,但定义了“序列化器”选项后,它似乎忽略了它。
我想做这样的事情,但是“ table_content”属性只是被忽略。
fos_elastica:
serializer:
serializer: jms_serializer
clients:
default: { host: localhost, port: 9200 }
indexes:
table_content:
types:
table_content:
properties:
id: ~
persistence:
driver: orm
model: TAMAS\AstroBundle\Entity\TableContent
astonomical_object:
types:
astonomical_object:
serializer:
groups: [astonomicalobject]
serialize_null: true
persistence:
driver: orm
model: TAMAS\AstroBundle\Entity\AstronomicalObject
答案 0 :(得分:0)
因此,实际上,当您在配置文件中手动映射类型时,FOSElastica确实可以识别类型,这对我来说是一个不好的理解。但这仍然很乏味,因为我在对象内的对象中有对象...
因此,一段时间后,我找到了解决问题的方法:Dynamic templates和Index templates
我实际上遇到了ElasticSearch无法识别某些类型的字段(例如date或geo_point)的麻烦,因此我借助模板将它们强制用于特定命名的字段。
如果要获取我在FOSElastica(doc is here)中的配置示例:
fos_elastica:
serializer:
serializer: jms_serializer
clients:
default:
host: localhost
port: 9200
index_templates: # https://www.elastic.co/guide/en/elasticsearch/reference/6.8/indices-templates.html
base_template: # this is a custom name for the index template
client: default
template: "*" # this is where you define which indices will use this template
types:
_doc: # this is where you define which types will use this (_doc stands for every type/documents)
dynamic_templates: # https://www.elastic.co/guide/en/elasticsearch/reference/6.8/dynamic-templates.html
dynamic_date_template: # this is a custom name for the dynamic field template
match_pattern: regex
match: created|updated|tpq_date|taq_date
mapping:
type: date
dynamic_location_template:
match: location
mapping:
type: geo_point