春季数据关系中的父/子实现

时间:2018-09-17 14:49:51

标签: spring-boot elasticsearch nosql mapping

我是Elasticsearch的新手,我试图弄清楚如何使用Spring Boot JPA映射我的关系 我有3个实体:用户,电影和评分。评分实体包含userid和movieid 我尝试了“父/子”实现,但我不知道在同一个子实体中可能有2个父。 实体:

   import lombok.*;
    import org.springframework.data.annotation.Id;
    import org.springframework.data.elasticsearch.annotations.Document;

    import java.io.Serializable;

    @Builder
    @Getter
    @Setter
    @AllArgsConstructor
    @NoArgsConstructor
    @ToString
    @Document(indexName = "movie-recommendation", type = "users")
    public class User implements Serializable {

        @Id
        private String id;
        private String username;
        private String password;

    }

import java.io.Serializable;


@Builder
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@ToString
@Document(indexName = "movie-recommendation", type = "ratings")
public class Rating implements Serializable {

    @Id
    private String id;
    private float rating;
    private String accordingTimestamp;

    @Parent(type = "users")
    private String userId;
    @Parent(type = "movies")
    private String movieId;


}

@Builder
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@ToString
@Document(indexName = "movie-recommendation", type = "movies")
public class Movie implements Serializable {

    @Id
    private String id;
    private String title;
    private String genre;
}

索引查询具有“ setParentId()”方法,但我应该有2个父母...:

Rating rating1 = Rating.builder().rating(5).accordingTimestamp("321321421321").movieId(movie1.getId()).userId(user1.getId()).build();
        IndexQuery ratingIndex1 = new IndexQuery();
        ratingIndex1.setId(rating1.getId());
        ratingIndex1.setObject(rating1);
        ratingIndex1.setParentId(???)

是否有可能在实体之间实现这种映射?

0 个答案:

没有答案