禁用仅针对弹性搜索的特定索引的动态映射创建? [英] Disable dynamic mapping creation for only specific indexes on elasticsearch?
问题描述
我试图禁用仅针对特定索引的动态映射创建,而不是全部。由于某种原因,我无法使用'dynamic':'false'放置默认映射。
所以,这里留下两个可以看到的选项:
I'm trying to disable dynamic mapping creation for only specific indexes, not for all. For some reason I can't put default mapping with 'dynamic' : 'false'. So, here left two options as I can see:
- 指定属性'index.mapper.dynamic' / em>在文件 elasticsearch.yml 中。
- 将'index.mapper.dynamic'在索引创建时间,如下所述 https://www.elastic.co/guide/en/kibana/当前/ setup.html#kibana-dynamic-mapping
- specify property 'index.mapper.dynamic' in file elasticsearch.yml.
- put 'index.mapper.dynamic' at index creation time, as described here 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 )。
First option may only accept values: true, false and strict. So there is no way to specify subset of specific indexes (like we do by pattern with property 'action.auto_create_index' https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-index_.html#index-creation).
第二个选项不起作用。
我创建了索引
Second option just not works. I've created index
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"
}
}
}
}
}
}
到目前为止这么好,让我们用未声明的字段索引文档:
so far so good, let's index document with undeclared field:
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"
}
然后我再次检查了地图:
Then I've checked mapping again:
GET http://localhost:9200/test_idx/_mapping
{
"test_idx" : {
"mappings" : {
"test_type" : {
"properties" : {
"field1" : {
"type" : "string"
},
"somefield" : {
"type" : "string"
}
}
}
}
}
}
正如你所看到的,映射是扩展的,无论索引设置dynamic:false。
我也试图按照doc
As you can see, mapping is extended regardless of index setting "dynamic" : false. I've also tried to create index exactly as described in doc
PUT http://localhost:9200/test_idx
{
"index.mapper.dynamic": false
}
but got the same behavior.
也许我错过了什么?
非常感谢提前!
推荐答案
你几乎在那里:值需要设置为 strict
。
正确的用法如下:
You're almost there: the value needs to be set to strict
.
And the correct usage is the following:
PUT /test_idx
{
"mappings": {
"test_type": {
"dynamic":"strict",
"properties": {
"field1": {
"type": "string"
}
}
}
}
}
再推一下,如果你想禁止创建即使是新的类型,不仅该索引中的字段使用这个:
And pushing this a bit further, if you want to forbid the creation even of new types, not only fields in that index, use this:
PUT /test_idx
{
"mappings": {
"_default_": {
"dynamic": "strict"
},
"test_type": {
"properties": {
"field1": {
"type": "string"
}
}
}
}
}
没有$ code> _default _ 模板:
Without _default_
template:
PUT /test_idx
{
"settings": {
"index.mapper.dynamic": false
},
"mappings": {
"test_type": {
"dynamic": "strict",
"properties": {
"field1": {
"type": "string"
}
}
}
}
}
这篇关于禁用仅针对弹性搜索的特定索引的动态映射创建?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!