not_analyzed 索引的弹性搜索 dynamic_templates
Elastic search dynamic_templates of not_analyzed index
我正在尝试为 Elastic Search 中的一个索引创建一个映射。
对于我文档的大部分元素,动态映射就足够了。但是对于我的维度对象中的每个键,我需要有一个 not_analyzed 索引。
一份文件的例子:
{"key1":"value1",
"dimensions": {"563a92a1b7f2b700196bd3cd":"G1",
"43214b7f2b700196bd3432":4321}}
在那种情况下,我希望动态映射 key1,但我的两个维度 not_analyzed。诀窍是我事先不知道维度的关键。所以我用的是动态模板。
我目前拥有的:
{
"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"
}
}
}
]
}
我正在尝试为 Elastic Search 中的一个索引创建一个映射。 对于我文档的大部分元素,动态映射就足够了。但是对于我的维度对象中的每个键,我需要有一个 not_analyzed 索引。
一份文件的例子:
{"key1":"value1",
"dimensions": {"563a92a1b7f2b700196bd3cd":"G1",
"43214b7f2b700196bd3432":4321}}
在那种情况下,我希望动态映射 key1,但我的两个维度 not_analyzed。诀窍是我事先不知道维度的关键。所以我用的是动态模板。
我目前拥有的:
{
"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"
}
}
}
]
}