[英]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.