我在Elasticsearch中将JSON字符串存储为对象,但是在requestPayload作为我们的JSON字符串正文的下面出现Exception:
[requestPayload]的对象映射尝试将字段[requestPayload]解析为对象,但发现了具体值
方法如下:
@Override
public PushBookingNotification save(PushBookingNotification pushBookingNotification) {
log.debug("Request to save PushBookingNotification : {}", pushBookingNotification);
PushBookingNotification result = pushBookingNotificationRepository.save(pushBookingNotification);
pushBookingNotificationSearchRepository.save(result);
return result;
}
====实体如下=====
公共(public)类PushBookingNotification实现了Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@NotNull
@Column(name = "ota_hotel_id", nullable = false)
private Long otaHotelId;
@Column(name = "hotel_name")
private String hotelName;
@NotNull
@Column(name = "reference_no", nullable = false)
private String referenceNo;
@NotNull
@Type(type = "jsonb")
@Column(name = "request_payload", columnDefinition = "jsonb", nullable = false)
@Field(type = FieldType.Object)
private String requestPayload;
// Getter和setter方法
=====错误日志=======
ERROR 10409 --- [ XNIO-2 task-11] c.atithih.cms.aop.logging.LoggingAspect : Exception in com.atithih.cms.service.impl.PushBookingNotificationServiceImpl.save() with cause = 'NULL' and exception = 'object mapping for [requestPayload] tried to parse field [requestPayload] as object, but found a concrete value'
org.elasticsearch.index.mapper.MapperParsingException: object mapping for [requestPayload] tried to parse field [requestPayload] as object, but found a concrete value
at org.elasticsearch.index.mapper.DocumentParser.parseObjectOrNested(DocumentParser.java:350)
at org.elasticsearch.index.mapper.DocumentParser.parseObjectOrField(DocumentParser.java:465)
at org.elasticsearch.index.mapper.DocumentParser.parseValue(DocumentParser.java:591)
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:529)
at org.elasticsearch.index.shard.IndexShard.prepareIndexOnPrimary(IndexShard.java:506)
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:1657)
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.transport.RequestHandlerRegistry.processMessageReceived(RequestHandlerRegistry.java:69)
at org.elasticsearch.transport.TransportService$7.doRun(TransportService.java:644)
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:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
最佳答案
为什么在字段requestPayload上具有此批注 @Field(type = FieldType.Object)。也许尝试删除它,它可能会起作用。