Is default dynamic mapping of documents okay?

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

The mappings show as:

Q1: Is this okay? And/or referring to Mapping | Elasticsearch Guide [8.1] | Elastic 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?

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;
 });

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.

PUT demo_idx
{
  "mappings": {
    "properties": {
      "bussiness": {
        "type": "nested",
        "properties": {
          "id":{
            "type": "keyword"
          },
          "attribute": {
            "type": "object"
          }
        }
      }
    }
  }
}
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"
    }
  ]
}

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

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