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

首先贴上文档:

{
    "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"
}

我最初设计成了如下的结构的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"
                }
            }
        }
    }
}

其中"online"字段需要设置成nested,然后子结构里面有个"platform"是个object,这个结构里面的字段不是固定的,有可能动态增加,所以我想不把它写死,按照这个mapping插入数据的时候直接报出了如下错误:

{
    "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"字段的问题,我想问下该怎么改映射,才能插入这个结构的数据?

阅读 5.3k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进