我们可以避免将所有字段都映射到springdata中用于Elasticsearch的实体类,因为json文档中有100多个字段吗? [英] Can we avoid mapping all the fields to entity class in springdata for elasticsearch, as I have more than 100 field in the json document?

查看:79
本文介绍了我们可以避免将所有字段都映射到springdata中用于Elasticsearch的实体类,因为json文档中有100多个字段吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用springdata API实现用于Elasticsearch(es)操作的spring-boot微服务.我在es中建立索引的文档很大,有多个字段(超过100个).

I am implementing a spring-boot microservice for elasticsearch (es) operations using springdata APIs. My documents that are indexed in es are huge with multiple fields (more than 100).

有没有一种方法可以避免为Java中的Elasticsearch对象定义/硬编码实体类中的所有字段?

Is there a way to avoid defining/hardcoding all the fields in the entity class for elasticsearch object in java?

我的示例患者JSON可能像这样:

My sample patient JSON could be like:

{
  "key_1":"value_1",
  "key_2":"value_2",
  "key_3":"value_3",
         .
         .
         .  

  "key_n":"value_n"
}

推荐答案

谢谢"@ P.J.Meisch",为我指明了正确的方向!

Thank you "@P.J.Meisch", for pointing me the right direction!

我通过执行文档(json)重构解决了该问题,该文档将在elasticsearch中建立索引.通过将匿名患者ID保留在根级别并将其余患者详细信息保留在子json中,可以完成此操作.下面是我的Model类.

I resolved the issue by performing document (json) restructuring, that will be indexed in elasticsearch. It was done by keeping the anonymised patient id at the root level and rest of the patient details in a sub json. Below is my Model class.

@Component
@Document(indexName = "manual_patients") // name must be lower case
@Getter
@Setter
@ToString(callSuper=true, includeFieldNames=true)
// @NoArgsConstructor
public class ManualPatient {

    @Id
    private String _id = UUID.randomUUID().toString();

    @ApiModelProperty(position = 0)
    private String patientId;

    private Map patientDetails;

    public ManualPatient(){}

    public ManualPatient( String patientId, Map patientDetails) {
        this.patientId = patientId;
        this.patientDetails = patientDetails;
    }
}

这篇关于我们可以避免将所有字段都映射到springdata中用于Elasticsearch的实体类,因为json文档中有100多个字段吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆