字段数据类型概括:
Elasticsearch支持一系列不同的数据类型来定义文档字段,分为核心数据、复杂数据、地理数据、专门数据类型。
核心数据类型包括:
字符串数据类型: string
数字型数据类型: long、 Integer、 short、byte、 double、float
日期型数据类型: date
布尔型数据类型: boolean
二进制数据类型: binary
复杂数据类型包括:
数组数据类型: 不需要专门的类型来定义数组。
对象数据类型: object,单独的JSON对象。
嵌套数据类型: nested,关于JSON对象的数组。
地理数据类型包括:
地理点数据类型: geo_point,经纬点。
地理形状数据类型: geo_shape,多边形的复杂地理形状。
专门数据类型包括:
IPv4数据类型:IP协议为IPv4的地址。
完成数据类型: completion,提供自动补全的建议。
单词计数数据类型: token_count,统计字符串中的单词数量。
字符串类型:
不分词
1 2 3 | "studymodel" : { "type" : "keyword" } |
分词
1 2 3 | "name" : { "type" : "text" } |
使用ik分词器
1 2 3 4 5 | "name" : { "type" : "text" , "analyzer" : "ik_max_word" , "search_analyzer" : "ik_smart" } |
组合类型,支持分词或不分词,以及ik分词
1 2 3 4 5 6 7 8 9 | "buildcorpname" : { "type" : "text" , "fields" : { "key" : { "type" : "keyword" } }, "analyzer" : "ik_max_word" } |
基本日期类型
1 2 3 | "properties" : { "date" : { "type" : "date" } } |
设置允许date字段存储年月日时分秒、年月日及毫秒两张种格式
1 2 3 4 | "timestamp" : { "type" : "date" , "format" : "yyyy‐MM‐dd HH:mm:ss||yyyy‐MM‐dd" } |
设置允许date字段存储年月日时分秒、年月日及毫秒三种格式,允许不指定日期格式
1 2 3 4 | "timestamp" : { "type" : "date" , "format" : "yyyy‐MM‐dd HH:mm:ss||yyyy‐MM‐dd||epoch_millis" } |
long类型,最小的整数
1 2 3 | "price" : { "type" : "long" } |
integer
1 2 3 | "price" : { "type" : "integer" } |
float
1 2 3 | "price" : { "type" : "float" } |
浮点数,对于浮点数尽量用比例因子,比如一个价格字段,单位为元,我们将比例因子设置为100这在ES中会按 分 存
储。
1 2 3 4 | "price" : { "type" : "scaled_float" , "scaling_factor" : 100 } |
double
1 2 3 | "price" : { "type" : "double" } |
bool类型
boolean
1 2 3 | "is_num" : { "type" : "boolean" } |
nested关联映射
1 2 3 4 5 6 7 8 | "project" : { "type" : "nested" , "properties" : { "localdate" :{ "type" : "date" } } } |
无论从事什么行业,只要做好两件事就够了,一个是你的专业、一个是你的人品,专业决定了你的存在,人品决定了你的人脉,剩下的就是坚持,用善良專業和真诚赢取更多的信任。