MapperParsingException[failed to parse [auditDate]]; nested: NumberFormatException[For input string: "2017-07-12 08:49:33"];
at org.elasticsearch.index.mapper.FieldMapper.parse(FieldMapper.java:298)
at org.elasticsearch.index.mapper.DocumentParser.parseObjectOrField(DocumentParser.java:450)
at org.elasticsearch.index.mapper.DocumentParser.parseValue(DocumentParser.java:576)
at org.elasticsearch.index.mapper.DocumentParser.innerParseObject(DocumentParser.java:396)
at org.elasticsearch.index.mapper.DocumentParser.parseObjectOrNested(DocumentParser.java:373)
at org.elasticsearch.index.mapper.DocumentParser.internalParseDocument(DocumentParser.java:93)
at org.elasticsearch.index.mapper.DocumentParser.parseDocument(DocumentParser.java:66)
at org.elasticsearch.index.mapper.DocumentMapper.parse(DocumentMapper.java:277)
at org.elasticsearch.index.shard.IndexShard.prepareIndex(IndexShard.java:536)
at org.elasticsearch.index.shard.IndexShard.prepareIndexOnPrimary(IndexShard.java:513)
at org.elasticsearch.action.bulk.TransportShardBulkAction.prepareIndexOperationOnPrimary(TransportShardBulkAction.java:450)
at org.elasticsearch.action.bulk.TransportShardBulkAction.executeIndexRequestOnPrimary(TransportShardBulkAction.java:458)
at org.elasticsearch.action.bulk.TransportShardBulkAction.executeBulkItemRequest(TransportShardBulkAction.java:143)
at org.elasticsearch.action.bulk.TransportShardBulkAction.shardOperationOnPrimary(TransportShardBulkAction.java:113)
at org.elasticsearch.action.bulk.TransportShardBulkAction.shardOperationOnPrimary(TransportShardBulkAction.java:69)
at org.elasticsearch.action.support.replication.TransportReplicationAction$PrimaryShardReference.perform(TransportReplicationAction.java:939)
at org.elasticsearch.action.support.replication.TransportReplicationAction$PrimaryShardReference.perform(TransportReplicationAction.java:908)
at org.elasticsearch.action.support.replication.ReplicationOperation.execute(ReplicationOperation.java:113)
at org.elasticsearch.action.support.replication.TransportReplicationAction$AsyncPrimaryAction.onResponse(TransportReplicationAction.java:322)
at org.elasticsearch.action.support.replication.TransportReplicationAction$AsyncPrimaryAction.onResponse(TransportReplicationAction.java:264)
at org.elasticsearch.action.support.replication.TransportReplicationAction$1.onResponse(TransportReplicationAction.java:888)
at org.elasticsearch.action.support.replication.TransportReplicationAction$1.onResponse(TransportReplicationAction.java:885)
at org.elasticsearch.index.shard.IndexShardOperationsLock.acquire(IndexShardOperationsLock.java:147)
at org.elasticsearch.index.shard.IndexShard.acquirePrimaryOperationLock(IndexShard.java:1656)
at org.elasticsearch.action.support.replication.TransportReplicationAction.acquirePrimaryShardReference(TransportReplicationAction.java:897)
at org.elasticsearch.action.support.replication.TransportReplicationAction.access$400(TransportReplicationAction.java:93)
at org.elasticsearch.action.support.replication.TransportReplicationAction$AsyncPrimaryAction.doRun(TransportReplicationAction.java:281)
at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37)
at org.elasticsearch.action.support.replication.TransportReplicationAction$PrimaryOperationTransportHandler.messageReceived(TransportReplicationAction.java:260)
at org.elasticsearch.action.support.replication.TransportReplicationAction$PrimaryOperationTransportHandler.messageReceived(TransportReplicationAction.java:252)
at org.elasticsearch.xpack.security.transport.SecurityServerTransportInterceptor$ProfileSecuredRequestHandler$1.doRun(SecurityServerTransportInterceptor.java:258)
at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37)
at org.elasticsearch.xpack.security.transport.SecurityServerTransportInterceptor$ProfileSecuredRequestHandler.messageReceived(SecurityServerTransportInterceptor.java:316)
at org.elasticsearch.transport.RequestHandlerRegistry.processMessageReceived(RequestHandlerRegistry.java:69)
at org.elasticsearch.transport.TransportService$7.doRun(TransportService.java:627)
at org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.doRun(ThreadContext.java:638)
at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NumberFormatException: For input string: "2017-07-12 08:49:33"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Long.parseLong(Long.java:589)
at java.lang.Long.parseLong(Long.java:631)
at org.elasticsearch.common.xcontent.support.AbstractXContentParser.longValue(AbstractXContentParser.java:172)
at org.elasticsearch.index.mapper.NumberFieldMapper$NumberType$7.parse(NumberFieldMapper.java:740)
at org.elasticsearch.index.mapper.NumberFieldMapper$NumberType$7.parse(NumberFieldMapper.java:719)
at org.elasticsearch.index.mapper.NumberFieldMapper.parseCreateField(NumberFieldMapper.java:1058)
at org.elasticsearch.index.mapper.FieldMapper.parse(FieldMapper.java:287)
... 39 more
问题原因:
定义的mapping格式与插入的格式不符合,定义的auditDate字段文本格式,插入时elasticsearch默认格式为long类型,类型转换异常,如比较mapping结果
解决方案:
1、修改mapping对应字段类型 如:
jsonMapping.append("\"createDate\": {");
jsonMapping.append("\"type\": \"date\",");
jsonMapping.append("\"format\": \"yyyy-MM-dd HH:mm:ss\"");
jsonMapping.append("},");
jsonMapping.append(" \"label\": {");
jsonMapping.append(" \"type\": \"text\",");
jsonMapping.append(" \"analyzer\": \"ik_smart\",");
jsonMapping.append(" \"search_analyzer\": \"ik_smart\",");
jsonMapping.append(" \"boost\": 8");
jsonMapping.append(" },");
jsonMapping.append("\"image\": {");
jsonMapping.append(" \"type\": \"keyword\"");
jsonMapping.append(" },");
jsonMapping.append(" \"title\": {");
jsonMapping.append("\"type\": \"text\",");
jsonMapping.append("\"analyzer\": \"word_like\",");
jsonMapping.append(" \"include_in_all\": \"true\",");
jsonMapping.append(" \"boost\": 8");
jsonMapping.append("}");
jsonMapping.append(" }");
jsonMapping.append("}");
PutMappingResponse putMappingResponse = client.admin().indices().preparePutMapping("sjh")
.setType("designerproduct").setSource(jsonMapping.toString(), XContentType.JSON).get();
if (putMappingResponse != null && putMappingResponse.isAcknowledged()) {
logger.info("创建索引sjh的类型designerproduct的映射字段成功");
}
2、修改新增方法时插入转换json
// 构造json对象
// JSONObject jsonObject = new JSONObject();
jsonObject.put("id", designerProduct.getId());
jsonObject.put("status", designerProduct.getStatus());
jsonObject.put("title", StringUtil.nullBlank(designerProduct.getTitle()));
jsonObject.put("image", StringUtil.nullBlank(designerProduct.getFrontImage()));
jsonObject.put("price", designerProduct.getPrice() == null ? 0 : designerProduct.getPrice());
jsonObject.put("buyout", designerProduct.getBuyout() == YesNoEnum.Y ? true : false);
jsonObject.put("browseCount",
designerProductTotal.getBrowseCount() == null ? 0 : designerProductTotal.getBrowseCount());
jsonObject.put("collectCount",
designerProductTotal.getCollectCount() == null ? 0 : designerProductTotal.getCollectCount());
jsonObject.put("saleCount",
designerProductTotal.getSaleCount() == null ? 0 : designerProductTotal.getSaleCount());
jsonObject.put("features", features == null ? null : features.toArray());
jsonObject.put("categoryId", designerProduct.getCategoryId());
jsonObject.put("designerId", designerProduct.getDesignerId());
jsonObject.put("auditDate",
designerProduct.getAuditDate() == null ? DateUtil.formatDate(new Date(), "yyyy-MM-dd HH:mm:ss")
: DateUtil.formatDate(designerProduct.getAuditDate(), "yyyy-MM-dd HH:mm:ss"));
jsonObject.put("unionLevel",
designerProductTotal.getUnionLevel() == null ? 0 : designerProductTotal.getUnionLevel());
jsonObject.put("score", designerProductTotal.getScore() == null ? new Date() : designerProductTotal.getScore());
jsonObject.put("label", designerFeature.toString());
return jsonObject;