【发布时间】:2015-11-24 23:40:13
【问题描述】:
我正在尝试使用动态用户创建的字段来索引一些数据。输入数据如下所示:
{ "kind": "feature",
"creationDate": 1424561126000,
"key" : "sdfgsdfg",
"user": {
"email" : "me@example.com",
"custom": {
"hello": "world",
"answer": 42,
"enable_the_thing": true
}
}
}
user.custom 对象中的键和值是动态的,甚至有可能某些实例对于同一个键具有不同类型的值。所以,我将它们翻译成这样的形状:
"custom": {
"hello": {
"stringVal": "world"
},
"answer": {
"numVal": 42
},
"enable_the_thing": {
"boolVal": true
}
}
(这样,我可以确定user.custom.hello.stringVal 将始终是一个字符串,即使另一个文档有一个数字user.custom.hello.numVal。)
到目前为止,这似乎有效。我将user.custom 的映射声明为:
{
"type": "object",
"dynamic": true
}
当我得到映射时,我看到这些动态字段是按预期创建的。
但是,我还需要保留所有这些值的未分析字符串表示形式。所以,我添加了一个像这样的动态映射模板(还有一个用于numVal 和boolVal 字段):
"custom_attribute_string": {
"mapping": {
"fields": {
"stringVal": {
"index": "analyzed",
"type": "string"
},
"untouched": {
"index": "not_analyzed",
"type": "string"
}
},
"type": "multi_field"
},
"path_match": "user.custom.*.stringVal"
}
但是,现在动态自定义字段没有在映射中创建,文档也没有被索引。
我怀疑我的映射模板有问题,但我不确定在哪里查看。我根据这些docs 创建了这个模板,但也许我应该寻找其他地方?
【问题讨论】:
标签: elasticsearch