我正在尝试仅针对特定索引禁用动态映射创建,而不是针对所有索引.出于某种原因,我不能将默认映射与'dynamic':'false' 放在一起.所以,我可以看到两个选项:
第一个选项可能只接受值:true,false和strict.所以没有办法指定特定索引的子集(就像我们通过带有属性'action.auto_create_index'的 模式一样' https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-index_.html#索引创建).
第二个选项不起作用.我创建了索引
POST http://localhost:9200/test_idx/
{
"settings" : {
"mapper" : {
"dynamic" : false
}
},
"mappings" : {
"test_type" : {
"properties" : {
"field1" : {
"type" : "string"
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
然后检查索引设置:
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"
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
和映射:
GET http://localhost:9200/test_idx/_mapping
{
"test_idx" : {
"mappings" : {
"test_type" : {
"properties" : {
"field1" : {
"type" : "string"
}
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
到目前为止很好,让我们的索引文档与未声明的字段:
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"
}
Run Code Online (Sandbox Code Playgroud)
然后我再次检查了映射:
GET http://localhost:9200/test_idx/_mapping
{
"test_idx" : {
"mappings" : {
"test_type" : {
"properties" : {
"field1" : {
"type" : "string"
},
"somefield" : {
"type" : "string"
}
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
如您所见,无论索引设置为"dynamic",都会扩展映射:false.我也尝试完全按照doc中的描述创建索引
PUT http://localhost:9200/test_idx
{
"index.mapper.dynamic": false
}
Run Code Online (Sandbox Code Playgroud)
但得到了相同的行为.
也许我错过了什么?
非常感谢提前!
And*_*fan 16
你几乎就在那里:需要设置值strict.正确的用法如下:
PUT /test_idx
{
"mappings": {
"test_type": {
"dynamic":"strict",
"properties": {
"field1": {
"type": "string"
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
并且进一步推动这一点,如果你想禁止创建新类型,不仅仅是该索引中的字段,请使用:
PUT /test_idx
{
"mappings": {
"_default_": {
"dynamic": "strict"
},
"test_type": {
"properties": {
"field1": {
"type": "string"
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
没有_default_模板:
PUT /test_idx
{
"settings": {
"index.mapper.dynamic": false
},
"mappings": {
"test_type": {
"dynamic": "strict",
"properties": {
"field1": {
"type": "string"
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
你必须知道,下面的部分只是意味着 ES 无法动态创建类型。
"mapper" : {
"dynamic" : false
}
Run Code Online (Sandbox Code Playgroud)
你应该像这样配置ES:
PUT http://localhost:9200/test_idx/_mapping/test_type
{
"dynamic":"strict"
}
Run Code Online (Sandbox Code Playgroud)
那么你就不能再索引其他没有映射的字段,并得到如下错误:
mapping set to strict, dynamic introduction of [hatae] within [data] is not allowed
Run Code Online (Sandbox Code Playgroud)
如果你想存储数据,但又让字段不能索引,可以这样设置:
PUT http://localhost:9200/test_idx/_mapping/test_type
{
"dynamic":false
}
Run Code Online (Sandbox Code Playgroud)
希望这些可以帮助有同样问题的人:)。
| 归档时间: |
|
| 查看次数: |
10228 次 |
| 最近记录: |