使用 FOSElastica 为特定实体定义 ElasticSearch 映射
Defining an ElasticSearch mapping for a particular entity with FOSElastica
我目前正在尝试使用 FOSElastica,但在配置方面遇到了问题。我想对我的大部分实体使用序列化程序,但我想为特定实体指定映射,我该怎么做?
我试过定义 "properties" 选项,但是定义了 "serializer" 选项后它似乎忽略了它。
我想做这样的事情,但是 "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
所以,事实上,当您在配置文件中手动映射时,FOSElastica 确实可以识别类型,这对我来说是一个错误的理解。但它仍然很乏味,因为我在对象中有对象......
所以,过了一段时间我找到了解决问题的方法:Dynamic templates and Index templates
实际上,我在 ElasticSearch 无法识别某些类型的字段(如日期或 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
我目前正在尝试使用 FOSElastica,但在配置方面遇到了问题。我想对我的大部分实体使用序列化程序,但我想为特定实体指定映射,我该怎么做?
我试过定义 "properties" 选项,但是定义了 "serializer" 选项后它似乎忽略了它。
我想做这样的事情,但是 "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
所以,事实上,当您在配置文件中手动映射时,FOSElastica 确实可以识别类型,这对我来说是一个错误的理解。但它仍然很乏味,因为我在对象中有对象......
所以,过了一段时间我找到了解决问题的方法:Dynamic templates and Index templates
实际上,我在 ElasticSearch 无法识别某些类型的字段(如日期或 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