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类型? 抹除掉后面 时间 ? 时间不是查询条件?
随机推荐
- java基础总结——基础语法2(语句)
1.1. 判断语句(if语句) 1.1.1. If语句的三种格式: 1.1.2. if语句特点: 每一种格式都是单条语句(单条不是单行,单条是一个整体). 第二种格式与三元运算符的区别:三 ...
- cloudera learning1:cloudera简介及安装
cloudera分为两个部分:CDH和CM.CDH是Cloudera Distribution Hadoop的简称,顾名思义,就是cloudera公司发布的Hadoop版本,封装了Apache Had ...
- JMeter学习-034-JMeter调试工具之一---HTTP Mirror Server
通常,编程工具IDE都提供了相应的调试模块,供开发者使用,以便更快速的定位问题所在.那么在JMeter编写测试脚本的过程中,JMeter都提供了哪些调试工具供我们使用呢? JMeter常用的调试工具有 ...
- 水的demo
- Android pop3与imap方式接收邮件(javamail)
需要下载3个jar包:mail.jar/ activation.jar/ additionnal.jar 1.pop3 /** * 以pop3方式读取邮件,此方法不能读取邮件是否为已读,已 ...
- ios 三种对话框拉伸方法
- AD10的PCB设计规则
PCB布线规则,布板需要注意的点很多,但是基本上注意到了下面的这此规则,LAYOUT PCB应该会比较好,不管是高速还是低频电路,都基本如此. 1. 一般规则 1.1 PCB板上预划分数字.模拟.DA ...
- ASP.NET MVC Web API For APP
近来很多大型的平台都公开了Web API.比如百度地图 Web API,做过地图相关的人都熟悉.公开服务这种方式可以使它易于与各种各样的设备和客户端平台集成功能,以及通过在浏览器中使用 JavaScr ...
- html特殊字符
平时写代码很少用到HTML的特殊字符,最常用的可能是 了,但有时在移动端为了节省时间,可能会用这些字符实现某种特殊效果,现整理如下: 使用方法: 这些字符属于unicode字符集,所以,你的文档需要声 ...
- Leetcode: Sentence Screen Fitting
Given a rows x cols screen and a sentence represented by a list of words, find how many times the gi ...