# Is default dynamic mapping of documents okay?

**URL:** <https://discuss.elastic.co/t/is-default-dynamic-mapping-of-documents-okay/301784>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [April 6, 2022, 4:45pm UTC](https://discuss.elastic.co/t/is-default-dynamic-mapping-of-documents-okay/301784 "2022-04-06T16:45:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ksuren](https://avatars.discourse-cdn.com/v4/letter/k/74df32/32.png) [@ksuren](https://discuss.elastic.co/u/ksuren)\
**Post date:** [April 6, 2022, 4:45pm UTC](https://discuss.elastic.co/t/is-default-dynamic-mapping-of-documents-okay/301784/1 "2022-04-06T16:45:24Z")

</div>

While creating a business listing data store, so far added Business and Categories to an index.

The mappings show as:

 ![Screen_Shot_2022-04-06_at_11_32_09_AM](https://us1.discourse-cdn.com/elastic/original/3X/8/c/8c3d58c126b8921e86f05aeac54ad8f4d9b5e3c4.png)

Q1: Is this okay? And/or referring to [Mapping | Elasticsearch Guide [8.1] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/8.1/mapping.html#mapping-limit-settings) should I create a custom map to group based on the object (business, category etc)? Because as I add more objects to the index, this list may increase.

Q2: I am using this Java example to create a new Business.. if I need to add a "business" map, how can I add?

```auto
final BulkResponse response = client.bulk(builder -> {
    for (Business business : businesses) {
        builder.index(indexName)
             .operations(ob -> {
                   if (business.getId() != null) {
                        ob.index(ib -> ib.document(business).id(business.getId()));
                   } else {
                        ob.index(ib -> ib.document(business));
                   }
                   return ob;
               });
    }
    return builder;
 });

```

---

<div class="post-metadata">

**Author:** ![RabBit\_BR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rabbit_br/32/82261_2.png) [@RabBit\_BR](https://discuss.elastic.co/u/RabBit_BR)\
**Post date:** [April 6, 2022, 5:08pm UTC](https://discuss.elastic.co/t/is-default-dynamic-mapping-of-documents-okay/301784/2 "2022-04-06T17:08:28Z")

</div>

You can create a type and add the characteristics of each object to the attributes array.  
When you create a new attribute you will not need to re-index your index.

```auto
PUT demo_idx
{
  "mappings": {
    "properties": {
      "bussiness": {
        "type": "nested",
        "properties": {
          "id":{
            "type": "keyword"
          },
          "attribute": {
            "type": "object"
          }
        }
      }
    }
  }
}

```

```auto
PUT demo_idx/_doc/2
{
  "id": 1,
  "attribute": [
    {
      "key": "name",
      "value": "business-01"
    },
    {
      "key": "phone",
      "value": "553656599"
    },
    {
      "key": "zip",
      "value": "0332326"
    },
    {
      "key": "state",
      "value": "any+state"
    }
  ]
}

```

---

<div class="post-metadata">

**Author:** ![ksuren](https://avatars.discourse-cdn.com/v4/letter/k/74df32/32.png) [@ksuren](https://discuss.elastic.co/u/ksuren)\
**Post date:** [April 6, 2022, 11:39pm UTC](https://discuss.elastic.co/t/is-default-dynamic-mapping-of-documents-okay/301784/3 "2022-04-06T23:39:12Z")

</div>

Thanks @RabBit_BR .  
I am using Java Client API, and wanted to learn how (and if we) can we add the "\_doc" via code? Using @spinscale 's example [elasticsearch-rest-client-samples/ProductServiceImpl.java at 3f41041d13a531207d2f8b520b09327e62417ae6 · spinscale/elasticsearch-rest-client-samples · GitHub](https://github.com/spinscale/elasticsearch-rest-client-samples/blob/3f41041d13a531207d2f8b520b09327e62417ae6/src/main/java/de/spinscale/restclient/ProductServiceImpl.java#L73)

---

<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:** [May 4, 2022, 11:39pm UTC](https://discuss.elastic.co/t/is-default-dynamic-mapping-of-documents-okay/301784/4 "2022-05-04T23:39:49Z")

</div>

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