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类型? 抹除掉后面 时间 ? 时间不是查询条件?
随机推荐
- cache-coherent nonuniform memory access
COMPUTER OR GANIZATION AND ARCHITECTURE DESIGNING FOR PERFORMANCE NINTH EDITION
- Codeforces 209 C. Trails and Glades
Vasya went for a walk in the park. The park has n glades, numbered from 1 to n. There are m trails b ...
- solr5.2 mysql 增量索引
前提:数据库里数据进行增删改操作时,相应的solr需要修改或者新建索引,之前从数据库中导入数据并创建索引的操作是全量创建,如果本身数据库数据量非常大,就需要增量创建索引 1./usr/local/sr ...
- Angular-ngtable
paginationMaxBlocks: XX, 最大显示页脚个数paginationMinBlocks: XX, 最小显示页脚个数
- jquery的$().each,$.each的区别
在jquery中,遍历对象和数组,经常会用到$().each和$.each(),两个方法.两个方法是有区别的,从而这两个方法在针对不同的操作上,显示了各自的特点. $().each,对于这个方法,在d ...
- css3知识
一.box-sizing 属性 规定两个并排的带边框的框 二.align-items (适用于父类容器上) 设置或检索弹性盒子元素在侧轴(纵轴)方向上的对齐方式. 值: flex-start:弹性盒子 ...
- JAVASE02-Unit09: 多线程基础
Unit09: 多线程基础 * 线程 * 线程用于并发执行多个任务.感官上像是"同时"执行 * * 创建线程有两种方式. * 方式一: * 继承线程并重写run方法来定义线程要执 ...
- SQLite如何测试
原文 http://www.sqlite.org/testing.html 目录 1. 介绍 1.1. 执行总结 2. 测试套件 3.异常测试 3.1 内存溢出测试 3.2 I/O错误测试 3.3 c ...
- js 四舍五入
举例excel: ROUND 会四舍五入的:ROUNDDOWN 取小数点后两位数据,不管进位问题:ROUNDUP 取小数点后两位数据,只要有第三位小数都会进位的.关键看你取数的要求 在js如果要求 ...
- T4
Text Template Transformation Toolkit T4语法感觉有点像aspx的视图模板<% %>. 使用可以通过VS扩展和更新安装"T4 Toolbox ...