我正在尝试仅针对特定索引禁用动态映射创建,而不是针对所有索引。出于某种原因,我不能放 默认 用'dynamic'映射:'false'。 所以,我可以看到两个选项:
- 指定属性 'index.mapper.dynamic' 在文件中 elasticsearch.yml。
- 放 'index.mapper.dynamic' 在索引创建时,如此处所述 https://www.elastic.co/guide/en/kibana/current/setup.html#kibana-dynamic-mapping
第一个选项可能只接受值:true,false和strict。因此,无法指定特定索引的子集(就像我们通过带有属性的模式一样) 'action.auto_create_index' https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-index_.html#index-creation)。
第二个选项不起作用。 我创建了索引
POST http://localhost:9200/test_idx/
{
"settings" : {
"mapper" : {
"dynamic" : false
}
},
"mappings" : {
"test_type" : {
"properties" : {
"field1" : {
"type" : "string"
}
}
}
}
}
然后检查索引设置:
GET http://localhost:9200/test_idx/_settings
{
"test_idx" : {
"settings" : {
"index" : {
"mapper" : {
"dynamic" : "false"
},
"creation_date" : "1445440252221",
"number_of_shards" : "1",
"number_of_replicas" : "0",
"version" : {
"created" : "1050299"
},
"uuid" : "5QSYSYoORNqCXtdYn51XfA"
}
}
}
}
和映射:
GET http://localhost:9200/test_idx/_mapping
{
"test_idx" : {
"mappings" : {
"test_type" : {
"properties" : {
"field1" : {
"type" : "string"
}
}
}
}
}
}
到目前为止这么好,让我们的索引文档与未声明的字段:
POST http://localhost:9200/test_idx/test_type/1
{
"field1" : "it's ok, field must be in mapping and in source",
"somefield" : "but this field must be in source only, not in mapping"
}
然后我再次检查了映射:
GET http://localhost:9200/test_idx/_mapping
{
"test_idx" : {
"mappings" : {
"test_type" : {
"properties" : {
"field1" : {
"type" : "string"
},
"somefield" : {
"type" : "string"
}
}
}
}
}
}
如您所见,无论索引设置为“dynamic”,都会扩展映射:false。 我也尝试完全按照doc中的描述创建索引
PUT http://localhost:9200/test_idx
{
"index.mapper.dynamic": false
}
但得到了相同的行为。
也许我错过了什么?
非常感谢提前!