Elasticsearch mapping映射文件设置没有生效
问题背景
咱们通常会预先建立 Elasticsearch index的 mapping.properties 文件(相似于MySQL中的表结构定义),app
mapping.properties 文件中定义了Elasticsearch索引设计到的字段及属性,通常为键值对格式 key=value。ui
key:定义每一个字段的名称spa
value:定义字段的属性(好比:integer,string,long,float,double,date等)debug
举例以下:设计
uuid=string索引
name=stringstring
可是,有时会发现,最终获取到的索引的mapping关系,并不是预先定义的。(意味着事先定义的mapping文件设置没有生效)ast
缘由分析
多是因为手误,在value后多了若干个空格,而程序中又没有使用 trim() 方法对value进行去空格处理。class
在debug程序的时候,会发现致使相似以下报错:date
No handler for type [string ] declared on field [fieldName]
此处意味着value值后有空格存在。
此时,只须要把 mapping.properties 文件中,存在的多余空格去除便可。