我需要将文档存储到 Elasticsearch 索引中,因此我定义了一个映射。从我的 java 客户端,我需要为它提供看起来像 Compony 类的 pojo。它有很多重复的值。我可以使用对象组合模式来解决这个问题,但 Elasticsearch 无法处理这种结构,因此它需要一个扁平结构。
class Company {
private String postalstreetName;
private String postalHouseNumer;
private String postalHouseLetter;
private String postalHouseNumberAddition;
private String postalZipCode;
private String postalCity;
private String postalCountry;
private String visitorstreetName;
private String visitorHouseNumer;
private String visitorHouseLetter;
private String visitorHouseNumberAddition;
private String visitorZipCode;
private String visitorCity;
private String visitorCountry;
private String establishmentstreetName;
private String establishmentHouseNumer;
private String establishmentHouseLetter;
private String establishmentHouseNumberAddition;
private String establishmentZipCode;
private String establishmentCity;
private String establishmentCountry;
}
我实际上想要像下面这样的 pojo,并以某种方式自动生成上面具有相同命名结构的 pojo。
class Address {
private String streetName;
private String houseNumer;
private String houseLetter;
private String houseNumberAddition;
private String zipCode;
private String city;
private String country;
}
class Company {
private Address postalAddress;
private Address visitorAddress;
private Address establishmentAddress;
}
有人知道这样的事情是否可能,从具有对象组合的 pojo 自动生成扁平 pojo,并为所有字段提供名称前缀?