Implementing the domain model

The implementation of the domain model Article using Elasticsearch annotations will look like the following:

@Document(indexName = "springboot2blog_article", type = "article")
@Data
public class Article {

@Id
private String id;

private String title;

private String link;

private String summary;

private String body;

@Field(type = FieldType.Nested)
private User author;

@Field(type = FieldType.Date)
private Date createdDate = new Date();

}

In the preceding code, @Document is used to mark the Article class as an Elasticsearch document with the index name "springboot2blog_article" and the type "article". The @Id annotation marks the ID property as the identity field of the document. The @Data annotation is from Lombok library and is used to mark a plain old Java object (POJO) as a class that will hold data. This means getters, setters, the equals method, the hashCode method, and the toString method will be generated for that class. The author field and the createdDate field are annotated with the @Field annotation, which specifies the type of those fields as they are complex, composite fields.

The implementation of the domain model User will look like the following:

@Document(indexName = "springboot2blog_user", type = "user")
@Data
@NoArgsConstructor
@AllArgsConstructor
public class User {

@Id
private String id;

private String username;

private String password;

private String role;

private String description;
}

The preceding class also does the same things as the User class. The newly added annotations, which are also from Lombok library and @AllArgsConstructor, will generate a constructor with the idusernamepasswordrole, and description properties and @NoArgsConstructor, which will generate a default constructor.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.117.93.0