我正在映射一个couchbase网关文档,我想告诉elasticsearch避免索引网关添加的内部属性,如“_sync”,这个对象包含另一个名为“channels”的对象,它具有以下形式:
"channels": {
"i7de5558-32ad-48ca-bf91-858c3a1e4588": 12
}
所以我猜这个对象的映射是这样的:
"channels": {
"type": "object",
"properties": {
"i7de5558-32ad-48ca-bf91-858c3a1e4588": {
"type": "integer",
"index": "not_analyze"
}
}
}
问题是键总是在变化,所以我不知道我是否应该为这个属性使用像这样的通配符 "*": {"type": "integer", "index": "not_analyze"} 或者做别的东西。
请问有什么建议吗?
最佳答案
如果字段是整数类型,则不必在映射中显式提供它们。您可以使用这些字段创建一个空映射、索引文档。 Elasticsearch 将推断字段的类型并动态更新映射。您也可以使用dynamic templates
为了这。
{
"mappings": {
"my_type": {
"dynamic_templates": [
{
"analysed_string_template": {
"path_match": "channels.*",
"mapping": {
"type": "integer"
}
}
}
]
}
}
}
关于elasticsearch - 如何在elasticsearch中映射动态字段值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35507741/