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类型? 抹除掉后面 时间 ? 时间不是查询条件?
随机推荐
- Servlet中的常用类以及常用方法
A:ServletConfig:用于读取Servlet在web.xml中配置的一些信息. getServletName(); getInitParameter();只能是Servlet自身下的参数设置 ...
- C#快捷键和注释
C#注释 //单行注释 /*....*/快注释 ///说明注释,一般用于封装的属性和方法上 #region和#endregion折叠注释,可以将代码折叠 static void ...
- Java 枚举7常见种用法
DK1.5引入了新的类型--枚举.在 Java 中它虽然算个"小"功能,却给我的开发带来了"大"方便. 用法一:常量 在JDK1.5 之前,我们定义常量都是: ...
- 1.Maven的安装以及本地仓库的配置
安装: maven下载地址:http://maven.apache.org/release-notes-all.html 然后解压,配置环境变量 MAVEN_HOME,并添加到path中.验证是否 ...
- 提取本地环境中部署RDLC的DLL
要使用reportviewer来呈现报表,需要有三个dll Microsoft.ReportViewer.WinForms.DLL Microsoft.ReportViewer.WebForms.DL ...
- CodeForces 676D代码 哪里有问题呢?
题目: http://codeforces.com/problemset/problem/676/D code: #include <stdio.h> #define MAXN 1001 ...
- Hibernate操作指南-实体之间的关联关系(基于注解)
- magereverse - Magento数据库表结构
Magento数据库表结构相当复杂,250多张表包含了非常多的表关联关系,让刚刚接触Magento的开发者来说真的非常头疼.往往是看到一个产品的各种属性分散在非常多的表中,找不到任何办法来取出它们的数 ...
- centos6.4 挂载新盘并移动mysql数据目录
1 centos 挂载新盘并格式化 以vmware workstation12 中安装的centos6. 虚拟机为例进行演示 关机,添加硬盘 开机,格式化硬盘,并挂载 通过命令查看硬盘 fdisk – ...
- Leetcode: Ones and Zeroes
In the computer world, use restricted resource you have to generate maximum benefit is what we alway ...