Elasticsearch mapping映射文件设置没有生效

Elasticsearch mapping映射文件设置没有生效


问题背景

我们一般会预先创建 Elasticsearch index的 mapping.properties 文件(类似于MySQL中的表结构定义),

mapping.properties 文件中定义了Elasticsearch索引设计到的字段及属性,一般为键值对格式 key=value

key:定义每个字段的名称

value:定义字段的属性(比如:integer,string,long,float,double,date等)

举例如下:

uuid=string

name=string

但是,有时会发现,最终获取到的索引的mapping关系,并非预先定义的。(意味着事先定义的mapping文件设置没有生效)


原因分析

可能是由于手误,在value后多了若干个空格,而程序中又没有使用 trim() 方法对value进行去空格处理。

在debug程序的时候,会发现导致类似如下报错:

No handler for type [string ] declared on field [fieldName]

此处意味着value值后有空格存在。

此时,只需要把 mapping.properties 文件中,存在的多余空格去除即可。

原文地址:https://www.cnblogs.com/miracle-luna/p/11427482.html