【发布时间】:2016-08-26 21:03:55
【问题描述】:
我在 elasticsearch 中创建索引时提供了一个默认映射动态模板,并想检查它是否按预期工作。让我难过,我如何验证它是否有效? (使用 ES 2.2.2)
"mappings": {
"_default_": {
"dynamic_templates": [
{
"no_date_detection": {
"match_mapping_type": "string",
"mapping": {
"type": "string",
"date_detection": false
}
}
},
{
"language_de": {
"match_mapping_type": "*",
"match": "*_de",
"mapping": {
"type": "string",
"analyzer": "german"
}
}
},
{
"language_es": {
"match": "*_es",
"match_mapping_type": "*",
"mapping": {
"type": "string",
"analyzer": "spanish"
}
}
},
{
"language_en": {
"match": "*_en",
"match_mapping_type": "*",
"mapping": {
"type": "string",
"analyzer": "english"
}
}
}
]
}
}
这非常简单,就像文档中提供的示例一样。
获取映射表明动态模板被传递给新类型
"testobject": {
"dynamic_templates": [
{
"no_date_detection": {
"mapping": {
"type": "string",
"date_detection": false
},
"match_mapping_type": "string"
}
},
{
"language_de": {
...
但是当我创建一个带有新字段的对象时 "description_en": "一些英文文本" 并获取它刚刚显示的映射
"description_en": {
"type": "string"
}
这不应该有 “分析器”:“英语” 在里面?
我做错了什么,如果我的动态映射是正确的,我如何验证它是否被应用?
提前致谢/Carsten
作为我的问题“我如何验证它是否被应用?”似乎不清楚,我尝试简化:
- 我使用默认动态映射创建索引。
- 我创建了一个类型“testobject”。
- “GET /myindex/testobject/_mappings”验证动态模板是否按预期传递给类型。
- 我在 testobject 类型的对象中创建了一个新字段。
- "GET /myindex/testobject/_mappings" 显示新字段,但没有说'"date_detection": false'。它将它显示为一个简单的字符串(见上文)。
如何验证动态模板是否/是否已应用于新创建的字段?
简化示例:
PUT /myindex
{
"mappings": {
"_default_": {
"dynamic_templates": [
{
"no_date_detection": {
"match_mapping_type": "string",
"mapping": {
"type": "string",
"date_detection": false
}
}
}
]
}
}
}
PUT /myindex/gardeners/1
{
"name": "gary"
}
GET /myindex/_mapping
{
"myindex": {
"mappings": {
"gardeners": {
"dynamic_templates": [
{
"no_date_detection": {
"mapping": {
"type": "string",
"date_detection": false
},
"match_mapping_type": "string"
}
}
],
"properties": {
"name": {
"type": "string"
}
}
},
"_default_": {
"dynamic_templates": [
{
"no_date_detection": {
"mapping": {
"type": "string",
"date_detection": false
},
"match_mapping_type": "string"
}
}
]
}
}
}
}
我的新字段“名称”的映射
"properties": {
"name": {
"type": "string"
}
}
不包含
"date_detection": false
为什么不流传下来?
【问题讨论】:
标签: elasticsearch