公司要做网站,建设网站的成本有哪些,北京旗网站制作,关注公众号在哪里查找1、说明
Elasticsearch的映射相当于数据库的数据字典#xff0c;它定义了每个字段的名称和能够保存的数据类型#xff0c;并且内置了20多种字段类型用于支持多种多样的结构化数据#xff0c;这里仅介绍几种常用的字段类型#xff0c;如需要了解全部的类型#xff0c;请参…1、说明
Elasticsearch的映射相当于数据库的数据字典它定义了每个字段的名称和能够保存的数据类型并且内置了20多种字段类型用于支持多种多样的结构化数据这里仅介绍几种常用的字段类型如需要了解全部的类型请参考官方文档的有关介绍。
2、Elasticsearch 映射类型
Elasticsearch 类型说明keyword它用于保存不经过分析、处理的原始文本texttext 这表示用于处理的原始文本可用于分词integer这是一个整型32位例如 1、2、3long这是一个长整型64位float这是一个浮点数32位例如 1.2 或 4.5double这是一个 double 类型浮点数64位boolean这是一个布尔值true 或 falsedate表示时间location表示经纬度list和json类型用{}括起来的是json数据类型用[]是数组类型binary用来存储二进制文件用来保存图片和文件
3、案例介绍
3.1 文本类型text和keyword
text存储会把切分后的文本保存到索引中如果没有分词一个个字的保存。 keyword 进行统计分析和精准搜索 PUT keyword-test{mappings: {properties: {name: {type: text}}}
}PUT keyword-test{mappings: {properties: {name: {type: keyword}}}
}3.2 时间类型以及数值类型、布尔类型
时间类型这个字段设置可以接收两种日期格式其中epoch_millis代表时间戳的毫秒数。注意这里都是UTC时间格式,时间有时区的问题
PUT sougoulog-date
{mappings: {properties: {visittime: {type: date,format: yyyy-MM-dd HH:mm:ss ||epoch_millis}}}
}数值类型
PUT obj-test
{mappings: {properties: {manager: {properties: {age: { type: integer }}}}}
}布尔类型
PUT test-2
{mappings: {properties: {sex: {type: boolean}}}
}3.3 json类型和数组类型
PUT obj-test
{mappings: {properties: {region: {type: keyword},manager: {properties: {age: { type: integer },name: {properties: {first: { type: text },last: { type: text }}}}}}}}PUT shopping/_doc/1
{tags: [ elastic, search ],lists: [{name: mylist,description: language list},{name: testlist,description: testlist}]
}3.4经纬度类型和二进制类型
PUT geo-1
{mappings: {properties: {location: {type: geo_point}}}
}PUT binary-test
{mappings: {properties: {pic: {type: binary}}}
}4、动态映射
看下面的例子就清楚了如果我们添加明显有特征的数据类型就会自动变成下面的数据类型
PUT number-test
{mappings: {numeric_detection: true}
}
PUT number-test/_doc/1
{price: 2.5,amount:2
}GET number-test/_mapping{number-test : {mappings : {numeric_detection : true,properties : {amount : {type : long},price : {type : float}}}}
}