简体   繁体   English

有没有一种方法可以配置Elasticsearch,以防止在特定索引中创建新类型?

[英]Is there a way to configure Elasticsearch so that it will prevent creating new type in specific index?

For example: I have index people and document type person-info . 例如:我有索引人员和文档类型person-info I explicitly defined its mapping by: 我通过以下方式明确定义了其映射:

curl -XPUT 'http://localhost:9200/people/_mapping/person-info' -d '
{
    "person-info" : {
        "properties" : {
            // some mapping
        }
    }
}

Once I inserted some documents to person_info instead of person-info by mistake. 一旦我将一些文档错误地插入了person_info而不是person-info So Elasticsearch automatically created new document type person_info with standart mapping which isn't appropriate for us. 因此,Elasticsearch自动使用标准映射自动创建了新的文档类型person_info ,它不适合我们。 There was no warnings about this, so I didn't notice that mistake in my code. 没有关于此的警告,因此我没有在代码中注意到该错误。 So now I have a lot of documents with different mapping. 所以现在我有很多具有不同映射的文档。

Is there a way to configure Elasticsearch so that it will prevent creating new type in specific index? 有没有一种方法可以配置Elasticsearch,以防止在特定索引中创建新类型?

Yes there is. 就在这里。 You can disable dynamic mapping by adding the following line in your elasticsearch.yml file. 您可以通过在elasticsearch.yml文件中添加以下行来禁用动态映射。

index.mapper.dynamic: false

Now if you try to index documents with type person_info , it will fail. 现在,如果您尝试使用person_info类型索引文档,它将失败。

No you cannot change this behaviour: this field is mandatory and when adding a new document it is used to index it. 不,您不能更改此行为:此字段是必填字段,并且在添加新文档时将其用作索引。 If the field were absent Elasticsearch would not know how to index the document. 如果缺少该字段,Elasticsearch将不知道如何为文档建立索引。 If a mapping for that type is missing a default one is created. 如果缺少该类型的映射,则会创建一个默认映射。

The only thing you can do is disabling the dynamic mapping creation: https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-dynamic-mapping.html 您唯一可以做的就是禁用动态映射创建: https : //www.elastic.co/guide/zh-CN/elasticsearch/reference/current/mapping-dynamic-mapping.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 有没有办法将文档索引到 Elasticsearch 并提交特定的_id? - Is there a way to Index a doc to Elasticsearch with a specific _id filed? Flume / Elasticsearch创建新索引,并忽略显式创建的索引 - Flume / Elasticsearch creating a new index and ignoring the index explicitly created 使用json不配置弹性搜索索引 - configure an elasticsearch index with json not taking Elasticsearch对特定索引的查询 - Elasticsearch query on a specific index 创建描述特定值的现有索引位置的新变量 - Creating new variables describing the existing index position of a specific value 当现有索引包含新索引中的所有列时,为什么创建此新索引可以提高性能? - Why did creating this new index improve performance so much when existing index included all columns in new index? 如何配置logstash创建弹性搜索索引? - How to configure logstash to create an elasticsearch index? 如何防止Elasticsearch限制索引? - How to prevent Elasticsearch from index throttling? 如何在ElasticSearch中创建索引时指定分析器 - How to specify an analyzer while creating an index in ElasticSearch 如何在Elasticsearch中使用新变量更新索引? - How to update an index with new variables in Elasticsearch?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM