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

**URL:** <https://discuss.elastic.co/t/eav-many-to-many-relationship-how-to-build-field-mapping/87968>\
**Category:** Elasticsearch\
**Created:** [June 1, 2017, 6:53pm UTC](https://discuss.elastic.co/t/eav-many-to-many-relationship-how-to-build-field-mapping/87968 "2017-06-01T18:53:54Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![johnson](https://avatars.discourse-cdn.com/v4/letter/j/d07c76/32.png) [@johnson](https://discuss.elastic.co/u/johnson)\
**Post date:** [June 1, 2017, 6:53pm UTC](https://discuss.elastic.co/t/eav-many-to-many-relationship-how-to-build-field-mapping/87968/1 "2017-06-01T18:53:55Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [June 29, 2017, 6:54pm UTC](https://discuss.elastic.co/t/eav-many-to-many-relationship-how-to-build-field-mapping/87968/2 "2017-06-29T18:54:21Z")

</div>

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