我在我的应用程序中使用 elasticsearch 进行索引。我正在尝试存储一个文档,该文档又包含一个自定义数据结构的字段:
@Document(indexName="sampleIndex", type="user")
class User {
@Id
private String id;
@Field(type = FieldType.Nested)
private Person person;
}
class Person {
String firstName;
String lastName;
}
我ElasticsearchRepository用来保存这个实体。lastName或firstNameof 有可能Person为空。在这种情况下,我得到一个NullPointerExceptionon call repository.save(entity)。有没有办法抑制这种情况?因为无论某些字段是否为空,我仍然想将其保存在 elasticsearch 上。