我正在尝试为Elastic Search中的索引之一创建映射。
对于我文档中的大多数元素,动态映射已经足够了。但是对于我的维度对象中的每个键,我需要具有一个not_analyzed索引。
一个文件的例子:
{"key1":"value1",
"dimensions": {"563a92a1b7f2b700196bd3cd":"G1",
"43214b7f2b700196bd3432":4321}}
在那种情况下,我希望key1被动态映射,但是我的两个维度都未进行分析。诀窍是我事先不知道尺寸的关键。所以我正在使用动态模板。
到目前为止,我有:
{
"dynamic_templates": [
{
"dimensions": {
"match": "dimensions.*",
"match_mapping_type": "string",
"mapping": {
"type": "string",
"index": "not_analyzed"
}
}
}
]
}
但这是行不通的。
任何的想法?
谢谢
最佳答案
当试图匹配另一个对象中字段的名称时,实际上需要使用 path_match
parameter而不是match
。因此,您的动态模板应如下所示:
{
"dynamic_templates": [
{
"dimensions": {
"path_match": "dimensions.*", <--- fix this line
"match_mapping_type": "string",
"mapping": {
"type": "string",
"index": "not_analyzed"
}
}
}
]
}
关于elasticsearch - not_analyzed索引的 Elasticsearch dynamic_templates,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34504291/