Type Self-Referential Relationships

I'm very confused with self-referencial types in Elasticsearch 6.2. Something simple, I want to create a family tree where I map myself to all my brothers. We're all of person type, so how can I connect this relationship?

Using the sample from the documentation, I have a mapping like below, but it doesn't work:

PUT people
{
  "mappings": {
    "person": {
      "properties": {
        "brothers": { 
          "type": "join",
          "relations": {
            "brother": "brother" 
          }
        }
      }
    }
  }
}

Maybe this isn't the best way to approach this? Essentially what I'd like to do is store the IDs of my brothers in my document, and when I search for my ID, they come back with my record, either through aggregation or part of my _source.

Any help would be appreciated...

The only way to create the relationship between brothers is by linking them with the same parent. Brother-to-brother relationship is N-to-N, and the join datatype supports only 1-to-N relationships.

Thanks Igor, what would you suggest in this scenario? Is there a way I can store an array of type string which would be the IDs of my brothers, but then return those records in my query?

Since they all live in the same index, is it possible?

I am not really sure what you are trying to achieve. What types of queries are you planning to run with this data?

In reality, it's products. If I sell a Raspberry Pi bundle that is composed of 3 different products, I'd like to get the parent products as well.

Can the same part be part of 2 different bundles? What kind of queries are you planning to run?

Yes, the same part could be part of 2 different bundles.

Here's another example: I run a pharmacy. All of my products have the same schema/type and live in the same index. On my pharmacy's website, a user searches for Tylenol, and clicks Tylenol PM. In this detail view, I would like to show the user metadata on the other products in the Tylenol family -- Tylenol Soft-Gel, Tylenol for Kids, Liquid Tylenol. Those would be the sibling products I would like to store in Tylenol PM's entry.

In this case, it sounds like just storing the family in a keyword field and then executing the second search using term filter to populate the detailed view would be the way to go.

That's what I thought, no way to combine it into one query though?

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