46.object类型

主要知识点

1field分类

2、object field类型的存储

一、field类型分类

1multivalue field

{ "tags": [ "tag1", "tag2" ]}

建立索引时与string是一样的,数据类型不能混

   

2empty field

   

null[][null]

   

3object field

es插入以下数据

PUT /company/employee/1

{

"address": {

"country": "china",

"province": "guangdong",

"city": "guangzhou"

},

"name": "jack",

"age": 27,

"join_date": "2017-01-01"

}

   

其中address就是object类型,也就是address里面是一个json格式的数据。

再执行GET /company/_mapping/employee,结果是:

{

"company": {

"mappings": {

"employee": {

"properties": {

"address": {

"properties": {

"city": {

"type": "text",

"fields": {

"keyword": {

"type": "keyword",

"ignore_above": 256

}

}

},

"country": {

"type": "text",

"fields": {

"keyword": {

"type": "keyword",

"ignore_above": 256

}

}

},

"province": {

"type": "text",

"fields": {

"keyword": {

"type": "keyword",

"ignore_above": 256

}

}

}

}

},

"age": {

"type": "long"

},

"join_date": {

"type": "date"

},

"name": {

"type": "text",

"fields": {

"keyword": {

"type": "keyword",

"ignore_above": 256

}

}

}

}

}

}

}

}

二、object field类型的存储

head进行查看,es是按以下方式进行存储:

{

"name": "jack",

"age": 27,

"join_date":"2017-01-01",

"address.country":"china",

"address.province": "guangdong",

"address.city":"guangzhou"

}

如果是更复杂的数据,如下面这条

{

"authors": [

{ "age": 26, "name": "Jack White"},

{ "age": 55, "name": "Tom Jones"},

{ "age": 39, "name": "Kitty Smith"}

]

}

在es内部存储方式如下:

{

"authors.age": [26, 55, 39],

"authors.name": [jack, white, tom, jones, kitty, smith]

}

   

原文地址:https://www.cnblogs.com/liuqianli/p/8471020.html