(1)string
string类型在ElasticSearch 旧版本中使用较多,从ElasticSearch 5.x开始再也不支持string,由text和keyword类型替代。
(2)text
当一个字段是要被全文搜索的,好比Email内容、产品描述,应该使用text类型。
设置text类型之后,字段内容会被分析,在生成倒排索引之前,字符串会被分析器分红一个一个词项。text类型的字段不用于排序,不多用于聚合。
(3)keyword
keyword类型适用于索引结构化的字段,好比email地址、主机名、状态码和标签。
若是字段须要进行过滤(好比查找已发布博客中status属性为published的文章)、排序、聚合。
keyword类型的字段只能经过精确值搜索到。node
类型 | 取值范围 |
---|---|
byte | -128~127 |
short | -32768~32767 |
integer | -2^31~2^31-1 |
long | -2^63~2^63-1 |
double,float ,half_float,scaled_float数组
UNIX在内部采用了一种最简单的计时方式app
ElasticSearch 内部会将日期数据转换为UTC,并存储为milliseconds-since-the-epoch的long型整数。 post
相关操做:code
1.建立索引 PUT test { "mappings":{ "my":{ "properties": { "postdate":{ "type":"date", "format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis" } } } } } 2.写入文档 PUT test/my/1 { "postdate":"2018-01-13" } PUT test/my/2 { "postdate":"2018-01-01 00:01:05" } PUT test/my/3 { "postdate":"1420077400001" } 3.批量查询 GET test/my/_mget { "ids":["1","2","3"] }
逻辑类型(布尔类型)能够接受true/false/”true”/”false”值orm
二进制字段是指用base64来表示索引中存储的二进制数据,可用来存储二进制形式的数据,例如图像。默认状况下,该类型的字段只存储不索引。二进制类型只支持index_name属性。对象
在ElasticSearch中,没有专门的数组(Array)数据类型,
可是,在默认状况下,任意一个字段均可以包含0或多个值,这意味着每一个字段默认都是数组类型排序
在同一个数组中,数组元素的数据类型是相同的,ElasticSearch不支持元素为多个数据类型:[ 10, “some string” ],经常使用的数组类型是:索引
(1)字符数组: [ “one”, “two” ]
(2)整数数组: productid:[ 1, 2 ]
(3)对象(文档)数组: “user”:[ { “name”: “Mary”, “age”: 12 }, { “name”: “John”, “age”: 10 }],ElasticSearch内部把对象数组展开为 {“user.name”: [“Mary”, “John”], “user.age”: [12,10]}ip
JSON天生具备层级关系,文档会包含嵌套的对象
DELETE test PUT test PUT test/my/1 { "employee":{ "age":30, "fullname":{ "first":"hadron", "last":"cheng" } } } GET /test/_mapping { "test": { "mappings": { "my": { "properties": { "employee": { "properties": { "age": { "type": "long" }, "fullname": { "properties": { "first": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } }, "last": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } } } } } } } } } } }
ip类型的字段用于存储IPv4或者IPv6的地址
PUT test { "mappings": { "my":{ "properties": { "nodeIP":{ "type": "ip" } } } } }