数据类型
String
字符串,根据是否将内容进行分词分为text与keyword两种
text
通过执行的分词器分析为多个词项,并建立倒排索引,因此无法用于排序、聚合操作。可以通过fileds属性建立不同类型的内嵌字段以满足需求
keyword
不会被es分词,直接存储。可以用于排序,比较、聚合等操作.
number
数字全部为有符号,且-0与+0是不相同得
整数:byte short int long
浮点数:double float half_float scaled_float
scaled_float暂未明白
并不是所有的数字都需要使用数字类型(具体实现待了解)
1、es对于数字范围查询进行了优化
2、es在keyword上进行term操作比数字更快
日期
date
在es中没有真正的日期格式,底层使用字符串、long得毫秒、interger得秒表示
对时间进行范围查询转换为long的毫秒范围查询
聚合查询使用格式化的数据(如yyyy-MM-dd)
时间在创建映射时会指定format格式,如果插入数据不符合指定格式会报错,可以有多个格式使用||分隔
PUT my_index
{
"mappings": {
"properties": {
"date": {
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"
}
}
}
}
date nanoseconds
对data的补充,以long类型存放了纳秒,表示范围为1970 to 2262
boolean
布尔类型:
false, "false", ""表示false值
true, "true"表示true值
binary
存放base64编码得数据,但无法用于搜索
range
范围存放数据比如 10<age<20
给定查询值15时可以获取到
object
某个字段得值仍为一个对象,映射如下
"mappings" : {
"properties" : {
"class" : {
"properties" : {
"name" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"num" : {
"type" : "long"
}
}
},
"name" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}
}
}
}
数据:
PUT object-index/_doc/1
{
"name":"jq",
"class":{
"name":"a"
,"num":1
}
}
nested
特殊得object,object为数组时防止交叉组合
比如数据为person:[{
"first" : "John",
"last" : "Smith"
},
{
"first" : "Alice",
"last" : "White"
}
]
当类型为object时:
"must": [
{ "match": { "user.first": "Alice" }},
{ "match": { "user.last": "Smith" }}
]
能够查询到结果,而nested时无法查询到结果

浙公网安备 33010602011771号