用一句话来概括,如何解决时间格式的字段,在新增数据往该字段插入空值,或者字符串格式类型的格式,在新增数据的时候,如何不检测新增的数据是否为时间格式,直接当作字符串格式存进去。
下面则是超详细复述:
{
"sjk": {
"mappings": {
"WorkFlow": {
"截止日期": {
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"
},
"MXProMoveModel": {
"BANJIETIME": {
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"
},
"PLANTIME": {
"type": "date",
}
}
}
}
}
}
上面是创建索引时自定义的属性,导入的json文件其格式如下(原文件是5000+条数据,在这只是取了其中一条):
{
"value": [
[
{
"受理编号": "20170000305",
"受理人员": "系统管理员",
"流程编号": "50.0",
"流程名称": "建设用地预审业务",
"受理类型ID": null,
"项目序号": 35.0,
"受理类型名称": null,
"项目名称": "33333333333333",
"所在地区": "克拉玛依市",
"所在地区编码": "650200",
"受理日期": "2017-11-21 16:14:06",
"截止日期": "2017-11-21 16:14:00",
"备注": null,
"项目编号": "2017-650200-00035",
"区域代码": "650200",
"区域名称": "克拉玛依市",
"创建时间": "2017-11-21 16:14:06",
"创建部门编号": "a8c860e3-f209-4818-999c-b25b7b9119c3",
"创建部门名称": "勘测信息中心",
"人员编号": "01379bf9-2406-4740-a8cb-e441dd39a556",
"申请单位": null,
"MXProLogModel": null,
"MXProNodeModel": [
{
"ID": "85ec6cbd-264e-4827-87d7-d2d27e1d5338",
"PROID": "20170000305",
"NODEID": 200.0,
"DEPTCODE": "a8c860e3-f209-4818-999c-b25b7b9119c3",
"DEPTNAME": "勘测信息中心",
"MOVEINTIME": "2017-11-21 16:14:06",
"MOVEOUTTIME": "2017-11-21 17:12:54",
"RETENTIONTIME": 58.0,
"PLANTIME": "2017-11-21 16:14:00",
"STATUS": 1.0,
"STIPULATETIME": 0.0,
"TYPE": 0,
"MoveModels": [ ]
},
{
"ID": "2a230cd4-319e-40cb-8554-10d6ef3a5459",
"PROID": "20170000305",
"NODEID": 202.0,
"DEPTCODE": "690ffe7c-ad19-4b3f-9443-9d9631137c1e",
"DEPTNAME": "局领导",
"MOVEINTIME": "2017-11-21 17:12:54",
"MOVEOUTTIME": "",
"RETENTIONTIME": 0.0,
"PLANTIME": "2017-11-21 17:12:00",
"STATUS": 0.0,
"STIPULATETIME": 0.0,
"TYPE": 0,
"MoveModels": [ ]
}
],
"MXProMoveModel": [
{
"ID": "e751c572-4598-472a-b17d-9b5c9c34d6cd",
"PROID": "20170000305",
"NODEID": 202.0,
"NODEDEPTCODE": "690ffe7c-ad19-4b3f-9443-9d9631137c1e",
"NODEDEPTNAME": "局领导",
"DEPTCODE": "690ffe7c-ad19-4b3f-9443-9d9631137c1e",
"DEPTNAME": "局领导",
"STAFFCODE": "9e6b73f6-0a9a-4791-b25f-99b797ad97bc",
"STAFFNAME": "王成功",
"MOVEDEPTCODE": "a8c860e3-f209-4818-999c-b25b7b9119c3",
"MOVEDEPTNAME": "勘测信息中心",
"MOVESTAFFCODE": "01379bf9-2406-4740-a8cb-e441dd39a556",
"MOVESTAFFNAME": "系统管理员",
"MOVEINTIME": "2017-11-21 17:12:54",
"PLANTIME": "2017-11-21 17:12:00",
"MOVEOUTTIME": "2018-01-08 10:03:46",
"RETENTIONTIME": 14001.0,
"OPER": "初审",
"TYPE": 0.0,
"SIGNTIME": "2017-11-21 17:34:27",
"STATUS": 2.0,
"Phone": ""
},
{
"ID": "2201c39f-a0f9-4ebf-9ead-96072b8bf9e0",
"PROID": "20170000329",
"NODEID": 33.0,
"NODEDEPTCODE": "1a380761-6fe6-462c-a259-c2a8a0e0e999",
"NODEDEPTNAME": "矿产管理科",
"DEPTCODE": "1a380761-6fe6-462c-a259-c2a8a0e0e999",
"DEPTNAME": "矿产管理科",
"STAFFCODE": "a5a1b3e1-9583-4859-9981-c9b5ecd5b381",
"STAFFNAME": "张天赐",
"MOVEDEPTCODE": "b15ac754-5019-481a-b7e5-30699fea8e9e",
"MOVEDEPTNAME": "土地储备(整理)中心",
"MOVESTAFFCODE": "d55a2d97-bb45-4af7-95fd-7d586ef007cc",
"MOVESTAFFNAME": "扎依旦",
"MOVEINTIME": "2017-11-23 23:52:25",
"PLANTIME": "",
"MOVEOUTTIME": "2017-11-23 23:56:06",
"RETENTIONTIME": 0.0,
"OPER": "承办",
"TYPE": 0.0,
"SIGNTIME": "2017-11-23 23:55:43",
"STATUS": 2.0,
"Phone": ""
}
],
"MXOperationModel": null,
"MXProInstModel": {
"PROID": "20170000305",
"PRONAME": "",
"WHZ": "",
"LWDW": "",
"TYPE": 0.0,
"OPERID": 0.0,
"OPERNAME": "",
"LATECODE": "",
"CREATESTAFFCODE": "",
"CREATESTAFFNAME": "",
"CREATETIME": "",
"STATUS": 0.0,
"CREATEDEPTCODE": "",
"CREATEDEPTNAME": "",
"USERN": "",
"PLANBANJIETIME": "",
"BANJIETIME": "",
"BEIZHU": "",
"JJCD": "",
"STOPTIME": "",
"STOPTIMEID": "",
"PREPROID": "",
"TMP": "",
"VerificationCode": ""
}
}
]
]}
我猜测是因为导入的PLANTIME这个字段,百度查了许久的答案,只有找到个类似的,解决方案是:把时间类型的设置成文本格式,并加上date-rich:false,因为我是刚开始接触这东西,所以不知道是我自己没写对还是加上了也没用。后面我只拿这一条数据测试,反复改了这个PLANTIME字段的值,均能正确导入
基本确定就是PLANTIME这个字段的类型问题了。我设置成date类型,如果值为空就会导入失败,设置为text类型,值为时间格式的就会失败,我设置成string类型,让es不把传进来的转成时间格式的,直接当字符串来存。如何写?
已解决。。。很恶心的情况。。我删除了重新建索引。设置字段类型是text,然后模拟一条类似的数据。报了同样的错。然后我把数据值全部改成空值,保存成功了。然后再改回去。保存成功了!导入5000条数据的JSON。成功!你没看错,同样的数据,保存成功了。我又重新建了个索引,索引名也换了,字段类型设置为text,保存成功!怪不得他一直提示该字段类型为date,合并成text报错。此处应有类似缓存的东西