行动是治愈恐惧的良药,而犹豫、拖延将不断滋养恐惧。

求助有关nested嵌套obj的mapping设置问题

Elasticsearch | 作者 abgrund | 发布于2018年11月28日 | 阅读数:4709

es版本5.6.3这个结构的文档doc:
{
"total": 5,
"online": [
{
"sid": "1101006",
"total": 0
},
{
"sid": "1101001",
"total": 2,
"platform": {
"Windows_2144": 1,
"Android_2144szsgnew": 1
}
},
{
"sid": "1101003",
"total": 1,
"platform": {
"Android_2144szsgnew": 1
}
},
{
"sid": "1101004",
"total": 2,
"platform": {
"Android_2144szsg": 2
}
},
{
"sid": "1101002",
"total": 0
},
{
"sid": "1101005",
"total": 0
}
],
"_t": "2018-11-26 00:00:00",
"groupid": "1101001"
}

 我在设置映射的时候"online"字段需要设置成nested,然后子结构里面有个"platform"是个object,这个结构里面的字段不是固定的,有可能动态增加,所以我想不把它写死,映射我设计成下面的结构,但是再插入数据的时候报错
{
"error": {
"root_cause": [
{
"type": "illegal_argument_exception",
"reason": "object mapping [online] can't be changed from nested to non-nested"
}
],
"type": "illegal_argument_exception",
"reason": "object mapping [online] can't be changed from nested to non-nested"
},
"status": 400
}
这个报错可以确定是"platform"字段的问题,我想问下该怎么改映射,才能插入这个结构的数据?
 
当前mapping:
{
"settings": {
"number_of_shards": 5,
"number_of_replicas": 0
},
"mappings": {
"doc": {
"dynamic": true,
"properties": {
"total": {
"type": "integer"
},
"online": {
"type": "nested",
"properties": {
"sid": {
"type": "keyword"
},
"total": {
"type": "integer"
},
"platform": {
"dynamic": true,
"type": "object"
}
}
},
"_t": {
"type": "date",
"format": "YYYY-MM-dd HH:mm:ss"
},
"groupid": {
"type": "keyword"
}
}
}
}
}
已邀请:

zz_hello

赞同来自:

ex6.4测试没问题啊,不会报错

laoyang360 - 《一本书讲透Elasticsearch》作者,Elastic认证工程师 [死磕Elasitcsearch]知识星球地址:http://t.cn/RmwM3N9;微信公众号:铭毅天下; 博客:https://elastic.blog.csdn.net

赞同来自:

第一步:删除索引
第二步:新建nested mapping索引,做好核对工作,
第三步:再次导入数据试试

要回复问题请先登录注册