Elasticsearch and a complex relationship

For design reasons, the relationship between my entities is as follows: Having entities A, B, C and AB where AB is the relationship many to many. I want to index the values of the entity C that has a many to many relationship with the B, starting from the relationship with A. I have a postgresql relational database and I am trying to map to elasticsearch but I can not find a way to do this and handle the relations may to many. Thanks in advance.

@Entity
public class A {
     ...

     @OneToMany(mappedBy = "a", cascade = CascadeType.ALL)
      private List<AB> b;
}

@Entity
 public class AB {
      ...

     @ManyToOne
     B b;
 }

@Entity
public class B {
    ...

   @ManyToMany
   private List<C> c;
}

@Entity
public class C {
    ...    // I want this indexes!!!

   @ManyToMany(mappedBy = "c")
   private List<B> b;
}

I'd totally forget about the existing model and would just think about the usage to build the right "search" objects for my use case.
Here I can't really answer as I don't know the use case and because it's not real objects.

Basically I'd recommend to ask yourself 2 questions:

  • What kind of objects my users want to get back as a response? If the answer is C then index a C object.
  • What typical attributes my users want to search for? B? Then store in the C object the content of the B object.

HTH

2 Likes

Thank you very much for answering, I will work based on your advice.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.