(EAV/Many-to-many relationship): how to build field mapping

Hello,I have a many-to-many relational database and wonder how I have to design my Documents in elasticsearch.

the data model in SQL looks like the following:

Product
-id
-name

Package
-id
-name

Attribute
-id
-name

Product can have several packages, and a package can have multiple attributes.

I understood that elasticsearch sees the world flat. So I wrote a small script that generates a JSON object for each product including all packages and attributes.

This looks as following:

    {
      "name": "product name",
      "Package 1": {
        "id": 1,
        "name": "package name",
        "Attribute 1":{
          "id": 1,
          "name": "attribute name"
         },
        "Attribute 2":{
          "id": 2,
          "name": "attribute name",
        }
      },
      "Package 2": {
        "id": 1,
        "name": "package name",
        "Attribute 3": {
          "id": 3,
          "name": [3, 5]
        }
    }
  }

The issue that I am having is that I don't know how many packages and attributes I have when I create my Type object. It might be that the next Document has a "Package 3" field.

So I wonder if can dynamically adjust my mapping setting for existing types ? If this is not possible, what else can I do to flexible build my documents from a many-to-many relationship ? Thanks, Johnson

1 Like

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