弹性搜索映射的包含机制
oarepo-mapping-includes的Python项目详细描述
OAREPO映射包括
这个包增加了对elasticsearch映射中包含的支持。在
示例
标题、摘要和描述是多语言字符串,看起来像
{ en: 'English version', cs: 'Czech version' }
由于elasticsearch不支持includes,因此这三个属性的映射
会相当大。使用这个库,您可以创建一个映射,例如
^{and> 包含的映射可能位于invenio内部,没有外部url,托管在web服务器上
并被http://或https://引用,甚至根据需要动态生成。在 这个库必须知道包含的映射(如果不是托管在外部服务器上)的位置。
在入口点中指定( 检查类型是外部资源(http://,https://)还是注册的内部资源
资源。如果没有,则保持原样,否则按以下方式得到定义: 然后,该定义与处于同一级别的任何其他元素合并,产生冲突
值被覆盖(想想python中的继承)。在 支持多种类型。在 其中 对于冲突,使用类似于python继承的算法 有时最好是动态创建映射。例如,
支持的语言数量因安装而异,并且
支持的语言在 在入口点中,定义 经办人签名: 处理程序可以返回字典或 如果它返回字典,它将与原始映射内容合并
(如额外属性等) 如果返回 如果处理程序希望转换原始内容,而不是简单地合并它,那么这是可用的。在 标签:// main mapping
{
"settings": {
"analysis": {
"oarepo:extends": "multilingual-v1.0.0.json#/analysis"
}
},
"mappings": {
"properties": {
"title": {
"type": "multilingual-v1.0.0.json#/text",
// extra properties for title might go here and are merged in
},
"description": {
"type": "multilingual-v1.0.0.json#/text"
},
"abstract": {
"type": "multilingual-v1.0.0.json#/text"
}
}
}
}
安装
pip install oarepo-mapping-includes
配置
my_repo
是存储库的顶级包):setup(# ...entry_points={"oarepo_mapping_includes":["my_repo = my_repo.mapping_includes"],"oarepo_mapping_handlers":["something_discussed_later = my_repo.mapping_handlers:dynamic"]})
包含的文件位置
oarepo_mapping_includes
应该具有以下结构,与invenio中的结构相同:my_repo
+- mapping_includes <-- as defined in entrypoint
+- v7 <-- ES version
+- multilingual-v1.0.0.json <-- this is referenced in type, oarepo:extends
支持的结构
type
#
部分)#
不是类型的一部分,则返回整个资源/
,则假定它是一个json指针
并被应用。返回json指针的结果。如果路径
不存在$id
属性的元素。错误
如果具有此id的元素不存在,则引发类型数组
{
// ...
"title": {
"type": [
"multilingual-v1.0.0.json#/text",
"copy-v1.0.0.json",
]
}
}
copy-v1.0.0.json
可能包含:{
"copy_to": "all_fields"
}
在oarepo:延伸
oarepo:extends
的行为方式与type
完全相同,但可以在映射中的任何地方使用动态处理程序
invenio.cfg
中指定oarepo_mapping_handlers
。“=”前的左手边
应该匹配type
,extend
。它可能是完整值或
#
之前的值。在defhandler(type=None,resource=None,id=None,json_pointer=None,app=None,content=None,root=None,content_pointer=None,**kwargs):""" :param type the type as literally written in "type" or "extends" properties :param resource part of the type before '#' :param id part of the type after '#' if it does not start with '/' :param json_pointer part of the type after '#' if it starts with '/' :param app current flask application. Use app.config to get the current config :param content json element containing the ``type`` :param root the whole mapping :param content_pointer json pointer of the content element :param **kwargs think of extensibility """return{...}
合并和替换内容
oarepo_mapping_includes.Mapping
的实例。在Mapping(mapping=<dict>, merge=True)
,参数merge
定义
原始映射内容将合并到(True
)中或完全替换(False
)。在推荐PyPI第三方库