Elasticsearch字段名称区分大小写 [英] Elasticsearch field name case sensitive

查看:80
本文介绍了Elasticsearch字段名称区分大小写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找有关ElasticSearch中字段名称区分大小写以及是否存在使字段名称不区分大小写的全局配置的建议和最佳实践.另外,如果映射中不存在ES,则可以禁止ES添加其他字段.

I am looking for advise and best practice regarding field name case sensitivity in ElasticSearch and whether there is a global configuration to make field names case insensitive. Also, if it is possible to disable ES from adding different fields if it does not exists in the mapping.

这是一个说明这一点的例子;

here is an example to illustrate the point;

1-用一个小写的名称"字段创建映射

1- create mapping with one field "name" in lowercase

curl -XPUT http://localhost:9200/twitter/user/_mapping -d '{ 
        "user" : { 
            "properties" : { 
            "name" : { "type" : "string" } 
        } 
    } 
}' 

2-为文档建立索引,对名称字段(NAME)使用不同的大小写

2- Index a document, using a different case for the name field (NAME)

curl -POST http://localhost:9200/twitter/user/1 -d '{ 
   "NAME" :  "Yasir" 
}'

在Elasticsearch日志中,我注意到映射已更新.

In the Elasticsearch logs, I noticed that the mapping is updated.

[2014-01-26 20:58:19,074][INFO ][cluster.metadata         ] [Mad-Dog] [twitter] update_mapping [user] (dynamic)

3-检查映射,您会注意到已添加一个新字段"NAME"

3- check the mapping, you will notice a new field has been added "NAME"

curl -XGET http://localhost:9200/twitter/user/_mapping?pretty

{
  "user" : {
    "properties" : {
      "NAME" : {
        "type" : "string"
      },
      "name" : {
        "type" : "string"
      }
    }
  }
}

谢谢Yasir

推荐答案

您可以禁止在配置中自动创建映射,就像提到的

You can disbale the automatic creation of the mapping in the configs, like mentioned in the documentation.

只需将 action.auto_create_index 设置为 false .

字段名称不能区分大小写,因为命名属于您.我建议只使用小写字母.但是,您可以搜索不区分大小写的值.

The field names can not be case-insensitive, since the naming belongs to you. I would suggest to only use lowercase for that. However, you can search in your values case-insensitive.

就像@javanna的评论所说,这不会禁用

Like @javanna's comment says, this does not disable the dynamic mapping. Therefore, you have to set index.mapper.dynamic to false.

因此,未声明的字段将被忽略.如果您想让Elasticsearch抛出错误,则必须将其设置为 strict .

As a result, non declared fields will be ignored. If you want elasticsearch to throw an error instead, you have to set it to strict.

这篇关于Elasticsearch字段名称区分大小写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆