【发布时间】:2016-01-20 16:59:00
【问题描述】:
我正在尝试仅为特定索引禁用动态映射创建,而不是全部禁用。出于某种原因,我不能将 default 映射与“动态”:“假”。 所以,这里留下了两个选项,我可以看到:
- 在文件 elasticsearch.yml 中指定属性 'index.mapper.dynamic'。
- 将 '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"
}
}
}
}
}
}
如您所见,无论索引设置如何,映射都会扩展“动态”:false。 我还尝试完全按照文档中的描述创建索引
PUT http://localhost:9200/test_idx
{
"index.mapper.dynamic": false
}
但行为相同。
也许我错过了什么?
提前非常感谢!
【问题讨论】:
-
抱歉,忘记版本了,我正在使用 elastic 1.5.2。
-
查看答案的最后一条评论,实际上是答案
-
"settings.mapper.dynamic": false禁用自动类型创建
标签: elasticsearch