Elasticsearch 动态模板无法按要求工作
Elasticsearch Dynamic template not working as required
我想要一个具有一些预定义字段(包括对象类型字段)的 elasticsearch 架构。我希望该对象类型字段中的所有字段默认为字符串。
我在创建索引时有以下映射和动态模板。
PUT myindex
{
"mappings": {
"doc": {
"dynamic_templates": [
{
"default_string": {
"path_match": "myObj.*",
"match_mapping_type": "*",
"mapping": {
"type": "text"
}
}
}],
"properties": {
"dummy_field_name": { "type": "text" },
"timestamp": {
"type": "date",
"format": "epoch_second"
},
"myObj": {
"type": "object"
}
}
}
}
}
但是当我在对象中提交一个带有数值的字段时,它并没有将该字段映射到字符串。
curl -XPOST "http://elastic-url:8080/myindex/test" -d
'{"dummy_field_name": "dymmy_value", "myObj":{ "filed_1": 123 ,
"field_2": "some value"}, "timestamp": 1522196333}'
"filed_1" 被标识为数字字段。但是我希望它存储为字符串类型。
Field types detected
您的映射是为类型 "doc" 定义的,但您正在索引类型 "test",请尝试匹配它们
我想要一个具有一些预定义字段(包括对象类型字段)的 elasticsearch 架构。我希望该对象类型字段中的所有字段默认为字符串。
我在创建索引时有以下映射和动态模板。
PUT myindex
{
"mappings": {
"doc": {
"dynamic_templates": [
{
"default_string": {
"path_match": "myObj.*",
"match_mapping_type": "*",
"mapping": {
"type": "text"
}
}
}],
"properties": {
"dummy_field_name": { "type": "text" },
"timestamp": {
"type": "date",
"format": "epoch_second"
},
"myObj": {
"type": "object"
}
}
}
}
}
但是当我在对象中提交一个带有数值的字段时,它并没有将该字段映射到字符串。
curl -XPOST "http://elastic-url:8080/myindex/test" -d
'{"dummy_field_name": "dymmy_value", "myObj":{ "filed_1": 123 ,
"field_2": "some value"}, "timestamp": 1522196333}'
"filed_1" 被标识为数字字段。但是我希望它存储为字符串类型。
Field types detected
您的映射是为类型 "doc" 定义的,但您正在索引类型 "test",请尝试匹配它们