ES数据-MySql处理Date类型的数据导入处理
用ES的小伙伴们,相信大家都遇到过Mapping处理Date类型的数据头疼问题吧。
不用头疼了,我来给你提供一种解决方案:
1、Maping定义为:
{
"mappings": {
"carecustomerlog_type_all": {
"properties": {
"ID": {
"type": "long"
},
"APPLYRATE": {
"type": "double"
},
"PREAPPLYRATE": {
"type": "double"
},
"TYPE": {
"type": "long"
},
"CDATE": {
"type": "long"
},
"CARECUSTOMID": {
"type": "long"
},
"CAREACCOUNTID": {
"type": "long"
},
"watenum": {
"type": "string",
"index": "not_analyzed"
},
"customerid": {
"type": "string",
"index": "not_analyzed"
},
"orderid": {
"type": "string",
"index": "not_analyzed"
},
"customername": {
"type": "string",
"index": "not_analyzed"
},
"content": {
"type": "string",
"index": "not_analyzed"
}
}
},
"careaccountin_type_all": {
"properties": {
"id": {
"type": "long"
},
"customerid": {
"type": "string",
"index": "not_analyzed"
},
"groupid": {
"type": "string",
"index": "not_analyzed"
},
"accountType": {
"type": "string",
"index": "not_analyzed"
},
"rate": {
"type": "double"
},
"amount": {
"type": "double"
},
"fee": {
"type": "double"
},
"sellerid": {
"type": "string",
"index": "not_analyzed"
},
"sellername": {
"type": "string",
"index": "not_analyzed"
},
"state": {
"type": "string",
"index": "not_analyzed"
},
"customername": {
"type": "string",
"index": "not_analyzed"
},
"createdate": {
"type": "string",
"index": "not_analyzed"
},
"groupname": {
"type": "string",
"index": "not_analyzed"
},
"adviserid": {
"type": "string",
"index": "not_analyzed"
},
"advisername": {
"type": "string",
"index": "not_analyzed"
},
"ordergroupid": {
"type": "string",
"index": "not_analyzed"
},
"ordergroupname": {
"type": "string",
"index": "not_analyzed"
},
"comm": {
"type": "string",
"index": "not_analyzed"
},
"watenum": {
"type": "string",
"index": "not_analyzed"
},
"appkey": {
"type": "string",
"index": "not_analyzed"
},
"paytime": {
"type": "long"
}
}
},
"carecustomerlog_type_funddetails": {
"properties": {
"ID": {
"type": "long"
},
"CDATE": {
"type": "long"
},
"orderid": {
"type": "string",
"index": "not_analyzed"
},
"PREAPPLYRATE": {
"type": "double"
},
"APPLYRATE": {
"type": "double"
},
"content": {
"type": "string",
"index": "not_analyzed"
},
"TYPE": {
"type": "long"
},
"CAREACCOUNTID": {
"type": "long"
},
"watenum": {
"type": "string",
"index": "not_analyzed"
},
"customerid": {
"type": "string",
"index": "not_analyzed"
},
"groupid": {
"type": "string",
"index": "not_analyzed"
},
"accountType": {
"type": "string",
"index": "not_analyzed"
},
"rate": {
"type": "double"
},
"amount": {
"type": "double"
},
"fee": {
"type": "double"
},
"sellerid": {
"type": "string",
"index": "not_analyzed"
},
"sellername": {
"type": "string",
"index": "not_analyzed"
},
"state": {
"type": "string",
"index": "not_analyzed"
},
"customername": {
"type": "string",
"index": "not_analyzed"
},
"createdate": {
"type": "string",
"index": "not_analyzed"
},
"groupname": {
"type": "string",
"index": "not_analyzed"
},
"adviserid": {
"type": "string",
"index": "not_analyzed"
},
"advisername": {
"type": "string",
"index": "not_analyzed"
},
"ordergroupid": {
"type": "string",
"index": "not_analyzed"
},
"ordergroupname": {
"type": "string",
"index": "not_analyzed"
},
"paytime": {
"type": "long"
}
}
}
}
}
在Mapping中把Date类型数据在es中定义成long类型。
在code中执行代码时,用MySql函数UNIX_TIMESTAMP(cai.paytime)获取日期的秒数据,插入到ES中
public static APIResult<String> save(String index, String type, String idName, JSONArray jsonArray)
{
BulkRequestBuilder bulkRequest = client.prepareBulk().setRefresh(true);
for (Iterator localIterator = jsonArray.iterator(); localIterator.hasNext(); ) { Object object = localIterator.next();
JSONObject json = StringUtils.isJSONObject(object);
String idValue = json.optString(idName);
if (StringUtils.isBlank(idValue)) {
idValue = idName;
}
if (StringUtils.isBlank(idName)) {
IndexRequestBuilder lrb = client.prepareIndex(index, type).setSource(json.toString());
bulkRequest.add(lrb);
}
else
{
IndexRequestBuilder lrb = client.prepareIndex(index, type, idValue).setSource(json.toString());
bulkRequest.add(lrb);
}
}
BulkResponse bulkResponse = null;
try {
bulkResponse = (BulkResponse) bulkRequest.execute().actionGet();
}
catch (Exception e) {
e.printStackTrace();
}
if (bulkResponse.hasFailures())
{
System.out.println(bulkResponse.getItems().toString());
return new APIResult(500, "保存ES失败!");
}
bulkRequest = client.prepareBulk();
return new APIResult(200, "保存ES成功!");
}
,执行添加,提醒一下ES默认会设置分词,在添加之前,应该首先定义Mapping,在执行添加。
然后就可以执行select、update、delete操作了。
ES数据-MySql处理Date类型的数据导入处理的更多相关文章
- 向mysql中插入Date类型的数据
先看数据库表的定义 date字段为sql.date类型.我要向其中插入指定的日期和当前日期. 一.插入当前日期 思路:先获取当前系统,在将当前系统时间转换成sql类型的时间,然后插入数据库.代码如下 ...
- oracle中时间戳转为Date类型的数据
问题描述: 一个表中原本应该存放date类型的数据,但是不知道之前哪位大仙把两个字段的类型建成了NUMBER类型的了,这样在后台看时间肯定不方便.现在需要改成date类型,但是现在库中是有数据的,不能 ...
- 使用js处理后台返回的Date类型的数据
从后台返回的日期类型的数据,如果直接在前端进行显示的话,显示的就是一个从 1970-01-01 00:00:00到现在所经过的毫秒数,而在大多数业务中都不可能显示这个毫秒数,大多数都是显示一个正常的日 ...
- 向数据库中插入一个DateTime类型的数据到一个Date类型的字段中,需要转换类型。TO_DATE('{0}','YYYY-MM-DD'))
需要指出的是,C#中有datetime类型,但是这个类型是包括小时,分钟,秒的.这个格式与数据库中的Date类型不符,如果将now设为datetime类型插入数据会失败. 需要通过TO_DATE('字 ...
- Android向Rest服务Post数据遇到的Date类型数据问题
今天在Android端向Rest服务Post数据时,总是不成功,查了很多资料,才知道Rest端将json串反序列化时,需要的时间格式必须是UTC类型,及Date(12345678+0800)格式. A ...
- 使用springmvc从页面中获取数据,然后根据获得的参数信息进行修改,如果修改的数据中含有不是基本数据类型的参数。比如传的参数中有Date类型的数据时,需要我们进行参数类型转换。
1.1 需求 在商品修改页面可以修改商品的生产日期,并且根据业务需求自定义日期格式. 1.2 需求分析 由于日期数据有很多格式,所以springmvc没办法把字符串转换成日期类型.所以需要自定义参数绑 ...
- 关于Java读取mysql中date类型字段默认值'0000-00-00'的问题
今天在做项目过程中,查询一个表中数据时总碰到这个问题: java.sql.SQLException:Value '0000-00-00' can not be represented as ...
- MySQL中date类型的空值0000-00-00和00:00:00
1.如果mysql中使用了date类型,并且默认值为'0000-00-00', 那么数据库中的'0000-00-00 00:00:00', '0000-00-00', '00:00:00'这三个值是相 ...
- 如何查询mysql中date类型的时间范围记录?
java date类型 会不会自动转换 mysql date类型? 抹除掉后面 时间 ? 时间不是查询条件?
随机推荐
- Mysql中字段类型不一致导致索引无效
修改后 详细见楼下链接 http://ustb80.blog.51cto.com/6139482/1287847
- Android界面组件的四种启动方式
Android界面组件启动有四种方式 standard,singleTop,singleTask,singleInstance. standard:每次调用都会都会产生新的组件. singletop: ...
- smarty中使用truncate出现乱码,用mb_substr解决
- jquery懒加载jquery.lazyload.js
Lazy Load 是一个用 JavaScript 编写的 jQuery 插件. 它可以延迟加载长页面中的图片. 在浏览器可视区域外的图片不会被载入, 直到用户将页面滚动到它们所在的位置. 这与图片预 ...
- vim - save current file with a new name but keep editing current file
http://superuser.com/questions/414110/vim-save-a-file-as-a-different-filename-but-keep-w-as-the-curr ...
- centos7 web服务器内核优化
net.ipv4.tcp_syn_retries = 1net.ipv4.tcp_synack_retries = 1net.ipv4.tcp_keepalive_time = 600net.ipv4 ...
- (转)CMOS Sensor的调试经验分享
CMOS Sensor的调试经验分享 我这里要介绍的就是CMOS摄像头的一些调试经验. 首先,要认识CMOS摄像头的结构.我们通常拿到的是集成封装好的模组,一般由三个部分组成:镜头.感应器和图像信号处 ...
- 批判性思维——Asking The Right Questions
我们生活在一个纷繁复杂的数字世界中,每天都在信息海洋中遨游.如果不想被其淹没,继而成为别人思想的傀儡,就有必要对你接受的信息进行批判.筛选,自己决定该相信什么不该相信什么,进而形成自己的观点,而不是一 ...
- 寿司点餐系统Sprint1总结
为期十天的一个冲刺,说长不长,说短不短.从一开始的接收课程任务到第一次聚集讨论. 确定方案.实行方案,再到最后的决定结束第一个冲刺,都是大家一起讨论着加小小的默契一步步 向前.没有完美,但是总体完成的 ...
- tar压缩
tar 压 缩:tar -jcv -f filename.tar.bz2 要被压缩的文件或目录名称 查 询:tar -jtv -f filename.tar.bz2 解压缩:tar -jxv -f f ...