存入JSON对象
在现实中我们常常会遇到各种复杂对象,比如:
{
"region": "ZH-CN",
"manager": {
"age": 30,
"name": {
"first": "John",
"last": "Smith"
}
}
}
实际上,我们在ES内部是用K-V的形式存储的,所以在内部其实是这样存储的:
实际上这有点像properties的格式。
{
"region": "US",
"manager.age": 30,
"manager.name.first": "John",
"manager.name.last": "Smith"
}
在Mapping的内部是这样存储的:
{
"mappings": {
"my_type": {
"properties": {
"region": {
"type": "keyword"
},
"manager": {
"properties": {
"age": { "type": "integer" },
"name": {
"properties": {
"first": { "type": "text" },
"last": { "type": "text" }
}
}
}
}
}
}
}
}
存入JSON对象数组
假如有以下JSON对象
{
"group" : "fans",
"user" : [
{
"first" : "John",
"last" : "Smith"
},
{
"first" : "Alice",
"last" : "White"
}
]
}
this is a typical json object array
在ES中这个JSON对象数组将会被解析成如下:
{
"group" : "fans",
"user.first" : [ "alice", "john" ],
"user.last" : [ "smith", "white" ]
}
该博客介绍了如何在ElasticSearch中存储JSON对象和对象数组。存入JSON对象时,ES内部以K-V形式存储,类似于properties格式,并展示了Mapping的内部结构。而对于JSON对象数组,博客解释了ES如何解析并存储此类数据。
6373

被折叠的 条评论
为什么被折叠?



