10 Kasım 2020 Salı

SpringData ElasticSearch @Field Anotasyonu

type Alanı
Double, Integer,  Nested, Text gibi değerler alabilir.

Örnek
Şöyle yaparız
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
@Document(indexName = "book")
public class Book {
  @Id
  private String id;

  @Field(type = FieldType.Text, name = "title")
  private String title;

  @Field(type = FieldType.Integer, name = "page")
  private Integer page;

  @Field(type = FieldType.Text, name = "isbn")
  private String isbn;

  @Field(type = FieldType.Text, name = "description")
  private String description;

  @Field(type = FieldType.Text, name = "language")
  private String language;

  @Field(type = FieldType.Double, name = "price")
  private Double price;
}
Örnek - Nested
Şöyle yaparız.
@Document(indexName = "blog", type = "article")
public class Article {
  @Id
  private String id;
  private String title;
  @Field(type = FieldType.Nested, includeInParent = true)
  private List<Author> authors;
   // standard getters and setters
}
Açıklaması şöyle
The authors field is marked as FieldType.Nested. This allows us to define the Author class separately, but have the individual instances of author embedded in an Article document when it is indexed in Elasticsearch.
Author sınıfı şöyledir
public class Author {

  @Field(type = Text)
  private String name;
    ...
}

Hiç yorum yok:

Yorum Gönder