elasticsearch - 仅针对 elasticsearch 上的特定索引禁用动态映射创建?

标签 elasticsearch

我正在尝试仅针对特定索引禁用动态映射创建,而不是针对所有索引。出于某种原因,我无法将 default 映射设置为“dynamic”:“false”。 因此,如我所见,这里留下了两个选项:

  1. 在文件 elasticsearch.yml 中指定属性 'index.mapper.dynamic'
  2. 在索引创建时放置'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
}

但得到了相同的行为。

也许我错过了什么?

提前致谢!

最佳答案

您快完成了:需要将值设置为 strict。 正确的用法如下:

PUT /test_idx
{
  "mappings": {
    "test_type": {
      "dynamic":"strict",
      "properties": {
        "field1": {
          "type": "string"
        }
      }
    }
  }
}

更进一步,如果你想禁止创建新类型,不仅是索引中的字段,使用这个:

PUT /test_idx
{
  "mappings": {
    "_default_": {
      "dynamic": "strict"
    },
    "test_type": {
      "properties": {
        "field1": {
          "type": "string"
        }
      }
    }
  }
}

没有_default_模板:

PUT /test_idx
{
  "settings": {
    "index.mapper.dynamic": false
  },
  "mappings": {
    "test_type": {
      "dynamic": "strict",
      "properties": {
        "field1": {
          "type": "string"
        }
      }
    }
  }
}

关于elasticsearch - 仅针对 elasticsearch 上的特定索引禁用动态映射创建?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33263673/

相关文章:

elasticsearch - 如何从 ElasticSearch 创建两个级别的 Grafana 变量?

elasticsearch - 当字段不存在时让 ElasticSearch 忽略过滤器

json - 在logstash中解析嵌套的json

elasticsearch - Kibana-设置JSON输入以获取最新的

grails - 使用 elasticsearch 0.19.8 在 EC2 中发起 war 时出现奇怪的结果

elasticsearch - Spring Data支持的ElasticSearch版本

elasticsearch - 按文本字段搜索

elasticsearch - Grafana无法在String字段上聚合,因为它无法识别Elasticsearch中的关键字字段

elasticsearch - 按字母顺序对关键字建立索引列表VS在Elasticsearch中根本不排序?

elasticsearch - 如果在特定时间没有任何反应,则DateHistogram Facet返回零