Pergunta

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- create mapping with one field "name" in lowercase

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

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

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

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- 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"
      }
    }
  }
}

Thanks Yasir

Foi útil?

Solução

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

Just set action.auto_create_index to 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.

EDIT:

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

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.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top